<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="jquery-mobile-1.4.4/jquery.mobile-1.4.4.min.css">
  <style type="text/css">
    /* max-width */
    @media screen and (max-width: 600px) { .par {font-size: 40px; } }
    /* min-width */
    @media screen and (min-width: 900px) { .par {font-size: 100px; } }
    /* min-width & max-width */
    @media screen and (min-width: 600px) and (max-width: 900px) { .par {font-size: 60px; } }
  </style>
  <script src="jquery-mobile-1.4.4/jquery.min.js"></script>
  <script src="jquery-mobile-1.4.4/jquery.mobile-1.4.4.min.js"></script>
<script>
$(document).ready(function(){
  // 全局变量
  var maxtime=5000; //每个项目测试的时间；测试时超过该时间，该次测试被判定为不合格。
  var timer; //计时
  var score=0; //分数
  var res = "";
  var first_number=0;                // 第一个数
  var second_number=0;               // 第二个数
  var third_number=0;                // 第三个数
  var fourth_number=0;               // 第四个数
  var plus_sign = "+";
  var minus_sign = "-";
  var times_sign = "×";
  var division_sign = "÷";
  var equals_sign = "=";
  var blank = "____";
  var result=0;                      // 正确答案
  var user_answer=0;                 // 用户输入的答案
  var horizontal_type="";            //  横式的内容
  var pre_horizontal_type="";            //  上一个横式的内容
  var horizontal_type_fail = [];     // 做错的横式
  var result_fail = [];              // 做错的横式的正确答案
  var last_btn = "";                 // 上一次点击的按钮
  var ht_length = 0;                 // 横式绘图区的长度

    // 检查用户答案
    function check_answer(){
      if ($(".par").text()==""){alert("请点击上面的按钮，以便生成题目");return false;};
      //获取用户输入的答案
      user_answer = "空值";
      for (var i=0; i<$(".input_class").length; i++){
        var input_class_val = $(".input_class").eq(i).val();
        if (input_class_val != ""){user_answer = input_class_val};
      }
      //判断对错，并作出反应
      if (result == user_answer){
        ++score;
        $(".right-top-count").html(function(){return score});
        $(".par").html("");
        $(".input_class").val("");
        var pass_msg = "棒极了！\n" + horizontal_type + "的答案正是" + result + "\n再来一道";
	if(last_btn=="#btn_test_fail"){
          var index_fail=horizontal_type_fail.indexOf(res);
	  horizontal_type_fail.splice([index_fail],1);
	  result_fail.splice([index_fail],1);
	};
        var r = confirm(pass_msg);
	if(r==true){$(last_btn).click();}else{$(last_btn).focus();return false;};
      }else{
	if (horizontal_type_fail.indexOf(horizontal_type) == -1){
          horizontal_type_fail.push(horizontal_type);
	  result_fail.push(result);
	};
        var fail_msg = "不是" + user_answer + "哦！\n再想想？"
        alert(fail_msg);
        $(".input_class").val("");
        $(".input_class").focus();
      };
    };
    $(".btn_check").click(function(){check_answer()});
  //起步：10以内各数的认识和加减
  //10以内各个数的加法
  $("#btn_10_meet_add").click(function(){
    var is_addend_include = $("#addend").val();
    var set_top_number = parseInt($("#set_top_number_unit_0").val());
    var set_number = set_top_number + 1;
    do{
      if (is_addend_include == "on"){
        do{
        first_number = Math.floor(Math.random()*set_number);
        second_number = Math.floor(Math.random()*(set_number - first_number));
        result = first_number + second_number;
        }while(result > set_top_number)
      }else{
        do{
        first_number = Math.floor(Math.random()*set_number);
        second_number = Math.floor(Math.random()*(set_number - first_number));
        result = first_number + second_number;
        }while(result != set_top_number)
      };
      horizontal_type = first_number + " + " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " + " + second_number + " = " + result; //测试运算结果。
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  //10以内各个数的减法
  $("#btn_10_meet_subtract").click(function(){
    var is_addend_include = $("#addend").val();
    var set_top_number = parseInt($("#set_top_number_unit_0").val());
    var set_number = set_top_number + 1;
    do{
      if (is_addend_include == "on"){
        first_number = Math.floor(Math.random()*set_number);
        second_number = Math.floor(Math.random()*(first_number+1));
        result = first_number - second_number;
      }else{
        first_number = set_top_number;
        second_number = Math.floor(Math.random()*set_number);
        result = first_number - second_number;
      };
      horizontal_type = first_number + " - " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " - " + second_number + " = " + result; //测试运算结果。
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  //第一单元：10以内的加减运算
  //10以内的加法
  $("#10_add").click(function(){
    var set_top_number = 10;
    var set_number = set_top_number + 1;
    do{
      do{
        first_number = Math.floor(Math.random()*set_number);
        second_number = Math.floor(Math.random()*(set_number-first_number));
        result = first_number + second_number;
      }while(result>set_top_number);
      horizontal_type = first_number + " + " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " + " + second_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  //10以内的减法
  $("#10_substract").click(function(){
    var set_top_number = 10;
    var set_number = set_top_number + 1;
    do{
      do{
        first_number = Math.floor(Math.random()*set_number);
        second_number = Math.floor(Math.random()*first_number+1);
        result = first_number - second_number;
      }while(result<0);
      horizontal_type = first_number + " - " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " - " + second_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  //10以内的三个数连加法
  $("#10_serial_add").click(function(){
    var set_top_number = 10;
    var set_number = set_top_number + 1;
    do{
      do{
        first_number = Math.floor(Math.random()*set_top_number);
        second_number = Math.floor(Math.random()*(set_number-first_number));
        third_number = Math.floor(Math.random()*(set_number-first_number-second_number));
        result = first_number + second_number + third_number;
      }while(result>set_top_number);
      horizontal_type = first_number + " + " + second_number + " + " + third_number + " =";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " + " + second_number + " + " + third_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  //10以内的三个数连减法
  $("#10_serial_substract").click(function(){
    var set_top_number = 10;
    var set_number = set_top_number + 1;
    do{
      do{
        first_number = Math.floor(Math.random()*set_number);
      }while(first_number < 2);
      do{
        do{
          second_number = Math.floor(Math.random()*first_number);
        }while(second_number < 1);
        temp_result =first_number-second_number;
      }while(temp_result<1);
      do{
      third_number = Math.floor(Math.random()*(temp_result+1));
      }while(third_number < 1);
      result = first_number - second_number - third_number;
      horizontal_type = first_number + " - " + second_number + " - " + third_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " - " + second_number + " - " + third_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  //10以内的三个数加减混合连续运算法
  $("#10_serial_add_and_substract").click(function(){
    var set_top_number = 10;
    var set_number = set_top_number + 1;
    var temp_result =0;
    var operators=[" + ", " - "];
    var operator_index = Math.floor(Math.random()*operators.length);
    var first_operator = operators[operator_index];
    operators.splice(operator_index, 1);
    do{
      if (first_operator == " + "){
        do{
          first_number = Math.floor(Math.random()*set_number);
          second_number = Math.floor(Math.random()*set_number);
          var temp_result = first_number + second_number;
        }while(temp_result>set_top_number);
        third_number = Math.floor(Math.random()*temp_result);
        result = temp_result - third_number;
      }else{
        do{
          first_number = Math.floor(Math.random()*set_number);
          second_number = Math.floor(Math.random()*set_number);
          var temp_result = first_number - second_number;
        }while(temp_result<0);
        do{
        third_number = Math.floor(Math.random()*(set_number-temp_result));
        result = temp_result + third_number;
        }while(result > set_top_number);
      };
      horizontal_type = first_number + first_operator + second_number + operators + third_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + first_operator + second_number + operators + third_number + " = " + result; //测试运算结果。
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  //第二单元：11~20各数的认识
  // 20以内不进位加法
  $("#btn_20_not_carry_add").click(function(){
    var set_top_number = 20;
    var set_number = set_top_number + 1;
    do{
      do{
        first_number = Math.floor(Math.random()*set_number);
        if(first_number<10){
          second_number = Math.floor(Math.random()*11+10)
        }else{
          second_number = Math.floor(Math.random()*(set_number-first_number));
        };
        result = first_number + second_number;
      }while(result>set_top_number || result < 10);
      horizontal_type = first_number + " + " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " + " + second_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 20以内不退位减法
  $("#btn_20_not_abdication_substract").click(function(){
    var set_top_number = 20;
    var set_number = set_top_number + 1;
    do{
      do{
        first_number = Math.floor(Math.random()*11+10);
        second_number = Math.floor(Math.random()*first_number);
        result = first_number - second_number;
      }while(result<10);
      horizontal_type = first_number + " - " + second_number + " =";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " - " + second_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  //20以内的三个数不进位连加法
  $("#btn_20_not_carry_serial_add").click(function(){
    var set_top_number = 20;
    var set_number = set_top_number + 1;
    do{
      first_number = Math.floor(Math.random()*11);
      second_number = 10-first_number;
      third_number = Math.floor(Math.random()*(set_number-10));
      result = first_number + second_number + third_number;
      horizontal_type = first_number + " + " + second_number + " + " + third_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " + " + second_number + " + " + third_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  //20以内的三个数不退位连减法
  $("#btn_20_not_abdication_serial_substract").click(function(){
    var set_top_number = 20;
    var set_number = set_top_number + 1;
    do{
      first_number = Math.floor(Math.random()*11+10);
      second_number = first_number-10;
      third_number = Math.floor(Math.random()*11);
      result = first_number - second_number - third_number;
      horizontal_type = first_number + " - " + second_number + " - " + third_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " - " + second_number + " - " + third_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  //20以内的三个数不进退位加减混合连续运算法
  $("#btn20_not_c_and_ab_serial_add_and_substract").click(function(){
    var set_top_number = 10;
    var set_number = set_top_number + 1;
    var temp_result =0;
    var operators=[" + ", " - "];
    var operator_index = Math.floor(Math.random()*operators.length);
    var first_operator = operators[operator_index];
    operators.splice(operator_index, 1);
    do{
      if (first_operator == " + "){
          first_number = Math.floor(Math.random()*11);
          second_number = 10-first_number;
        third_number = Math.floor(Math.random()*11);
        result = 10 - third_number;
      }else{
          first_number = Math.floor(Math.random()*11+10);
          second_number = first_number - 10;
        third_number = Math.floor(Math.random()*11);
        result = 10 + third_number;
      };
      horizontal_type = first_number + first_operator + second_number + operators + third_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + first_operator + second_number + operators + third_number + " = " + result; //测试运算结果。
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  //第三单元：20以内的进位加法
    // 20以内的进位加法
  $("#btn_20_carry_add").click(function(){
    do{
      do{
        first_number = Math.floor(Math.random()*10);
        second_number = Math.floor(Math.random()*10);
        result = first_number + second_number;
      }while(result<11);
      horizontal_type = first_number + " + " + second_number + " =";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " + " + second_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  //20以内进位连加法 
  $("#btn_20_carry_serial_add").click(function(){
    var set_top_number = 20;
    var set_number = set_top_number + 1;
    do{
      do{
        first_number = Math.floor(Math.random()*10);
        do{
          second_number = Math.floor(Math.random()*10);
        }while(first_number + second_number == 10);
        do{
         third_number = Math.floor(Math.random()*(set_number-first_number-second_number));
        }while(third_number > 9);
        result = first_number + second_number + third_number;
      }while(result>set_top_number || result<11);
      horizontal_type = first_number + " + " + second_number + " + " + third_number + " =";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " + " + second_number + " + " + third_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
    //20以内的进位加减混合运算
  $("#btn_20_serial_carry_add_and_substract").click(function(){
    var set_top_number = 20;
    var set_number = set_top_number + 1;
    var temp_result =0;
    var operators=[" + ", " - "];
    var operator_index = Math.floor(Math.random()*operators.length);
    var first_operator = operators[operator_index];
    operators.splice(operator_index, 1);
    do{
      if (first_operator == " + "){
        do{
          first_number = Math.floor(Math.random()*10);
          second_number = Math.floor(Math.random()*10);
          var temp_result = first_number + second_number;
        }while(temp_result<11);
        do{
        third_number = Math.floor(Math.random()*10);
        }while(temp_result - third_number < 10);
        result = temp_result - third_number;
      }else{
        do{
          first_number = Math.floor(Math.random()*10);
          second_number = Math.floor(Math.random()*first_number);
          temp_result = first_number - second_number;
        }while(temp_result<2);
        do{
          third_number = Math.floor(Math.random()*10);
          result = temp_result + third_number;
        }while(result < 11);
      };
      horizontal_type = first_number + first_operator + second_number + operators + third_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + first_operator + second_number + operators + third_number + " = " + result; //测试运算结果。
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  //第四单元：20以内的退位减法
    // 20以内的退位减法
  $("#btn_20_abdication_substract").click(function(){
    var set_top_number = 20;
    var set_number = set_top_number + 1;
    do{
      do{
        first_number = Math.floor(Math.random()*10+11);
        second_number = Math.floor(Math.random()*10);
        result = first_number - second_number;
      }while(result > 9);
      horizontal_type = first_number + " - " + second_number + " =";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " - " + second_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 20以内的三个数退位连减运算
  $("#btn_20_abdication_serial_substract").click(function(){
    var set_top_number = 20;
    var set_number = set_top_number + 1;
    var temp_result=0;
    do{
      do{
        first_number = Math.floor(Math.random()*10+11);
        second_number = Math.floor(Math.random()*10);
        temp_result = first_number - second_number;
      }while(temp_result==10 || temp_result>18);
        if (temp_result > 10){
          do{
          third_number = Math.floor(Math.random()*10);
	  }while(third_number<((first_number - second_number)-9));
        }else{
          third_number = Math.floor(Math.random()*(first_number - second_number + 1));
        };
        result = first_number - second_number - third_number;
      horizontal_type = first_number + " - " + second_number + " - " + third_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " - " + second_number + " - " + third_number + " = " + result;  //测试
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  //十几减几的三个数进退位加减混合运算
  $("#btn20_c_and_ab_serial_add_and_substract").click(function(){
    var set_top_number = 20;
    var set_number = set_top_number + 1;
    var temp_result =0;
    var operators=[" + ", " - "];
    var operator_index = Math.floor(Math.random()*operators.length);
    var first_operator = operators[operator_index];
    operators.splice(operator_index, 1);
    do{
    if (first_operator == " + "){     //首先处理第一步是加法运算的
      first_number = Math.floor(Math.random()*17+2);   //防止第一个加数大于18
      if(first_number>9){                            //第一个数大于9时不进位， 则第二部必须退位。因此前两个数之和需要大于18
        do{
          second_number = Math.floor(Math.random()*11);
          temp_result = first_number + second_number;
        }while(temp_result>18);
        do{                                             //防止结果没有退位
          third_number = Math.floor(Math.random()*10);
          result = temp_result - third_number;
        }while(result > 9);
      }else{                                        // 第一个数小于等于9时第一步进位；否则第二部也无法退位。
        do{
          second_number = Math.floor(Math.random()*10);  //防止第二个数字大于9
          temp_result = first_number + second_number;
	}while(temp_result<11);
        do{
          third_number =  Math.floor(Math.random()*(temp_result));
          result = temp_result - third_number;
	}while(result>9)
      };
    }else{          //下面处理第一步相减的。
      first_number = Math.floor(Math.random()*17+2);
      if (first_number < 11){                        //第一个数小于11时是不退位减法
        do{
          second_number = Math.floor(Math.random()*first_number);  // 前两个数的差不能小于2
          temp_result = first_number - second_number;
	}while(temp_result<2);
	do{
	  third_number = Math.floor(Math.random()*10);  // 最后确保出现进位加法
          result = temp_result + third_number;
	}while(result<11);
      }else{                                      // 第一个数大于10时候
        do{
          second_number =  Math.floor(Math.random()*10);
          temp_result = first_number - second_number;
	}while(temp_result>9)                      //如果前两个数的差大于9，是不退位减法，后面将没有进位减法。
        third_number = Math.floor(Math.random()*(21-temp_result));
        result = first_number - second_number + third_number;
      };
    };
    horizontal_type = first_number + first_operator + second_number + operators + third_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + first_operator + second_number + operators + third_number + " = " + result; //测试运算结果。
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  //第五单元：100以内数的加减（一）
  //整十数加减整十数
  $("#100_round_add_and_abstract_round").click(function(){
    var set_top_number = 100;
    var operators=[" + ", " - "];
    var operator_index = Math.floor(Math.random()*operators.length);
    var first_operator = operators[operator_index];
    do{
    if (first_operator == " + "){
      do{
        first_number = Math.floor(Math.random()*11)*10;
        second_number = Math.floor(Math.random()*11)*10;
        result = first_number + second_number;
      }while(result>set_top_number);
    }else{
      do{
        first_number = Math.floor(Math.random()*11)*10;
        second_number = Math.floor(Math.random()*11)*10;
        result = first_number - second_number;
      }while(result<0);
    };
    horizontal_type = first_number + first_operator + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + first_operator + second_number + " = " + result; //测试运算结果。
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  //两位数加一位数
  $("#100_2_digit_add_1d").click(function(){
    do{
    do{
      first_number = Math.floor(Math.random()*100);
    }while(first_number<10);
    do{
      second_number = Math.floor(Math.random()*(101-first_number));
    }while(second_number>9);
    result = first_number + second_number;
    horizontal_type = first_number + " + " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " + " + second_number + " = " + result; //测试运算结果。
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  //两位数加整十数
  $("#100_2_digit_add_round").click(function(){
    do{
    do{
      first_number = Math.floor(Math.random()*91);
    }while(first_number<10);
    do{
      second_number = Math.floor(Math.random()*(101-first_number));
    }while((second_number%10) > 0 || second_number==0);
    result = first_number + second_number;
    horizontal_type = first_number + " + " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " + " + second_number + " = " + result; //测试运算结果。
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  //两位数减一位数
  $("#100_2_digit_subtract_1d").click(function(){
    do{
    do{
      first_number = Math.floor(Math.random()*101);
    }while(first_number<10);
    do{
      second_number = Math.floor(Math.random()*10);
    }while(second_number>9);
    result = first_number - second_number;
    horizontal_type = first_number + " - " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " - " + second_number + " = " + result; //测试运算结果。
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  //两位数减整十数
  $("#100_2_digit_subtract_round").click(function(){
    do{
    do{
      first_number = Math.floor(Math.random()*101);
    }while(first_number<10);
    do{
      second_number = Math.floor(Math.random()*first_number);
    }while( (second_number%10) > 0 || second_number == 0);
    result = first_number - second_number;
    horizontal_type = first_number + " - " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " - " + second_number + " = " + result; //测试运算结果。
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  //第六单元：100以内数的加减（二）
  //两位数加两位数
  $("#btn_100_2_digit_add_2d").click(function(){
    do{
    do{
      first_number = Math.floor(Math.random()*100);
    }while(first_number<10);
    second_number = Math.floor(Math.random()*(101-first_number));
    result = first_number + second_number;
    horizontal_type = first_number + " + " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " + " + second_number + " = " + result; //测试运算结果。
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  //两位数减两位数
  $("#btn_100_2_digit_subtract_2d").click(function(){
    do{
    do{
      first_number = Math.floor(Math.random()*101);
    }while(first_number<11);
    do{
      second_number = Math.floor(Math.random()*first_number);
    }while(second_number<10);
    result = first_number - second_number;
    horizontal_type = first_number + " - " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " - " + second_number + " = " + result; //测试运算结果。
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  //两位数的连加
  $("#btn_100_serial_add").click(function(){
    var set_top_number = 100;
    var set_number = set_top_number + 1;
    do{
      first_number = Math.floor(Math.random()*set_number);
      second_number = Math.floor(Math.random()*(set_top_number - first_number + 1));
      third_number = Math.floor(Math.random()*(set_top_number - first_number - second_number + 1));
      result = first_number + second_number + third_number;
      horizontal_type = first_number + " + " + second_number + " + " + third_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " + " + second_number + " + " + third_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  //两位数的连减
  $("#btn_100_serial_subtract").click(function(){
    var set_top_number = 100;
    var set_number = set_top_number + 1;
    do{
    do{
      first_number = Math.floor(Math.random()*set_number);
    }while(first_number<20);
    second_number = Math.floor(Math.random()*first_number);
    third_number = Math.floor(Math.random()*(first_number - second_number));
    result = first_number - second_number - third_number;
    horizontal_type = first_number + " - " + second_number + " - " + third_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " - " + second_number + " - " + third_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  //两位数的加减混合
  $("#btn_100_serial_add_and_substract").click(function(){
    var set_top_number = 100;
    var set_number = set_top_number + 1;
    var temp_result =0;
    var operators=[" + ", " - "];
    var operator_index = Math.floor(Math.random()*operators.length);
    var first_operator = operators[operator_index];
    operators.splice(operator_index, 1);
    do{
    if (first_operator == " + "){
      do{
        first_number = Math.floor(Math.random()*set_number);
        second_number = Math.floor(Math.random()*set_number);
        var temp_result = first_number + second_number;
      }while(temp_result>set_top_number);
      third_number = Math.floor(Math.random()*temp_result);
      result = temp_result - third_number;
    }else{
      do{
        first_number = Math.floor(Math.random()*set_number);
        second_number = Math.floor(Math.random()*set_number);
        var temp_result = first_number - second_number;
      }while(temp_result<0);
      do{
      third_number = Math.floor(Math.random()*(set_number-temp_result));
      result = temp_result + third_number;
      }while(result > set_top_number);
    };
    horizontal_type = first_number + first_operator + second_number + operators + third_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + first_operator + second_number + operators + third_number + " = " + result; //测试运算结果。
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  //第七单元：表内乘法
  //表内乘法
  $("#btn_9_mutiple").click(function(){
    var is_factor_include = $("#factor").val();
    var set_top_number = parseInt($("#set_top_number").val());
    var set_number = set_top_number + 1;
    do{
    if (is_factor_include == "on"){
      first_number = Math.floor(Math.random()*set_number);
    }else{
      first_number = set_top_number;
    };
      second_number = Math.floor(Math.random()*10);
      result = first_number * second_number;
    horizontal_type = first_number + " × " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " × " + second_number + " = " + result; //测试运算结果。
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  //表内乘法混合加减
  $("#btn_100_serial_multiple_add_and_substract").click(function(){
    var set_top_number = 100;
    var set_number = set_top_number + 1;
    var temp_result =0;
    var operators=[" + ", " - ", " × "];
    var operator_index = Math.floor(Math.random()*operators.length);
    var first_operator = operators[operator_index];
    do{
      switch (first_operator)
      {
      case " + ":
        operators = " × ";
        do{
          first_number = Math.floor(Math.random()*set_top_number);
          second_number = Math.floor(Math.random()*10);
          third_number = Math.floor(Math.random()*10);
          result = first_number + (second_number * third_number);
        }while(result>set_top_number);
        break;
      case " - ":
        operators = " × ";
        do{
          first_number = Math.floor(Math.random()*set_number);
          second_number = Math.floor(Math.random()*10);
          third_number = Math.floor(Math.random()*10);
          result = first_number - (second_number * third_number);
        }while(result<0);
        break;
      case " × ":
        first_number = Math.floor(Math.random()*10);
        second_number = Math.floor(Math.random()*10);
        var temp_result = first_number * second_number;
        operators = [" + ", " - "];
        operator_index = Math.floor(Math.random()*operators.length);
        operators = operators[operator_index];
	if (operators == " + "){
	  third_number = Math.floor(Math.random()*(set_top_number-temp_result));
	  result = temp_result + third_number;
	}else{
	  third_number = Math.floor(Math.random()*(temp_result+1));
          result = temp_result - third_number;
	};
        break;
      };
      horizontal_type = first_number + first_operator + second_number + operators + third_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + first_operator + second_number + operators + third_number + " = " + result; //测试运算结果。
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  //第八单元：表内除法
  //表内除法（一）
  $("#btn_6_divide").click(function(){
    var set_top_number = 5;
    var set_number = set_top_number + 1;
    do{
      result = Math.floor(Math.random()*set_top_number+1);
      second_number = Math.floor(Math.random()*set_top_number+1);
      first_number = result * second_number;
      horizontal_type = first_number + " ÷ " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " ÷ " + second_number + " = " + result; //测试运算结果。
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  //表内除法（二）
  $("#btn_9_divide").click(function(){
    var set_top_number = 9;
    var set_number = set_top_number + 1;
    do{
      do{
        result = Math.floor(Math.random()*set_number);
      }while(result<6);
      do{
        second_number = Math.floor(Math.random()*set_number);
      }while(second_number<6);
      first_number = result * second_number;
      horizontal_type = first_number + " ÷ " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " ÷ " + second_number + " = " + result; //测试运算结果。
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  //表内除法（总）
  $("#btn_9_divide_all").click(function(){
    var set_top_number = 9;
    do{
      result = Math.floor(Math.random()*set_top_number+1);
      second_number = Math.floor(Math.random()*set_top_number+1);
      first_number = result * second_number;
      horizontal_type = first_number + " ÷ " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " ÷ " + second_number + " = " + result; //测试运算结果。
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  //表内除法混合运算
  $("#btn_9_divide_serial").click(function(){
    var set_top_number = 100;
    var set_number = set_top_number + 1;
    var temp_result =0;
    var operators=[" + ", " - ", " × ", " ÷ "];
    var operator_index = Math.floor(Math.random()*operators.length);
    var first_operator = operators[operator_index];
    do{
      switch (first_operator)
      {
      case " + ":
        operators = " ÷ ";
        do{
          first_number = Math.floor(Math.random()*set_top_number);
	  var temp_result = Math.floor(Math.random()*9+1);
          third_number = Math.floor(Math.random()*9+1);
          second_number = temp_result * third_number;
          result = first_number + temp_result;
        }while(result>set_top_number);
        break;
      case " - ":
        operators = " ÷ ";
        do{
          first_number = Math.floor(Math.random()*set_number);
	  var temp_result = Math.floor(Math.random()*9+1);
          third_number = Math.floor(Math.random()*9+1);
          second_number = temp_result * third_number;
          result = first_number - (second_number / third_number);
        }while(result<0);
        break;
      case " × ":
        operators = " ÷ ";
        var temp_result_all = [4, 6, 8, 9, 12, 18, 24, 36];
        var temp_result_id = Math.floor(Math.random()*temp_result_all.length);
	var temp_result = temp_result_all[temp_result_id];
        do{
	  first_number = Math.floor(Math.random()*9+1)
	}while(temp_result%first_number!=0);
        second_number = temp_result/first_number;
	do{
	  third_number = Math.floor(Math.random()*9+1)
	}while(temp_result%third_number!=0 || third_number == first_number || third_number == second_number);
        result = temp_result / third_number;
        break;
      case " ÷ ":
	var temp_result = Math.floor(Math.random()*9+1);
        second_number = Math.floor(Math.random()*9+1);
        first_number = temp_result * second_number;
        var second_operators = [" + ", " - ", " × "];
        var second_operator_id = Math.floor(Math.random()*second_operators.length);
	operators = second_operators[second_operator_id];
        switch (operators)
	{
	case " + ":
	  third_number = Math.floor(Math.random()*(set_number - temp_result));
          result = temp_result + third_number;
          break;
	case " - ":
	  third_number = Math.floor(Math.random()*temp_result);
          result = temp_result - third_number;
          break;
	case " × ":
	  third_number = Math.floor(Math.random()*9+1)
          result = temp_result * third_number;
          break;
        };
        break;
      };
      horizontal_type = first_number + first_operator + second_number + operators + third_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + first_operator + second_number + operators + third_number + " = " + result; //测试运算结果。
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  //第九单元：万以内数的加减法（一）
  //整百整千数的加减
  $("#btn_hunds_thous_add_and_subtract").click(function(){
    var operators=[" + ", " - "];
    var operator_index = Math.floor(Math.random()*operators.length);
    var operator = operators[operator_index];
    do{
      if (operator == " + "){
        var first_number_ready = Math.floor(Math.random()*100+1);
        var second_number_ready = Math.floor(Math.random()*(100-first_number_ready+1));
	first_number = first_number_ready*100;
	second_number = second_number_ready*100;
        result = first_number + second_number;
      }else{
        var first_number_ready = Math.floor(Math.random()*100+1);
        var second_number_ready = Math.floor(Math.random()*first_number_ready+1);
	first_number = first_number_ready*100;
	second_number = second_number_ready*100;
        result = first_number - second_number;
      };
    horizontal_type = first_number + operator + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + operator + second_number + " = " + result; //测试运算结果。
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  //几百几十加减几百几十
  $("#btn_hunds_tens_add_and_subtract").click(function(){
    var operators=[" + ", " - "];
    var operator_index = Math.floor(Math.random()*operators.length);
    var operator = operators[operator_index];
    do{
      if (operator == " + "){
        var first_number_ready = Math.floor(Math.random()*100+1);
        var second_number_ready = Math.floor(Math.random()*(100-first_number_ready+1));
	first_number = first_number_ready*10;
	second_number = second_number_ready*10;
        result = first_number + second_number;
      }else{
        var first_number_ready = Math.floor(Math.random()*100+1);
        var second_number_ready = Math.floor(Math.random()*first_number_ready+1);
	first_number = first_number_ready*10;
	second_number = second_number_ready*10;
        result = first_number - second_number;
      };
    horizontal_type = first_number + operator + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + operator + second_number + " = " + result; //测试运算结果。
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  //第十单元：万以内数的加减法（二）
  // 1000内的加法
  $("#btn_1000_add").click(function(){
    var set_top_number = 1000;
    var set_number = set_top_number + 1;
    do{
      do{
        do{
        first_number = Math.floor(Math.random()*set_number);
	}while(first_number<100);
        second_number = Math.floor(Math.random()*(set_number-first_number));
        result = first_number + second_number;
      }while(result>set_top_number);
      horizontal_type = first_number + " + " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " + " + second_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  // 10000内的加法
  $("#btn_10000_add").click(function(){
    var set_top_number = 10000;
    var set_number = set_top_number + 1;
    do{
      do{
        do{
          first_number = Math.floor(Math.random()*set_number);
	}while(first_number<1000);
        second_number = Math.floor(Math.random()*(set_number-first_number));
        result = first_number + second_number;
      }while(result>set_top_number);
      horizontal_type = first_number + " + " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " + " + second_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 1000内的减法
  $("#btn_1000_subtract").click(function(){
    var set_top_number = 1000;
    var set_number = set_top_number + 1;
    do{
      do{
        do{
        first_number = Math.floor(Math.random()*set_number);
	}while(first_number<100);
        second_number = Math.floor(Math.random()*first_number+1);
        result = first_number - second_number;
      }while(result<0);
      horizontal_type = first_number + " - " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " - " + second_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 10000内的减法
  $("#btn_10000_subtract").click(function(){
    var set_top_number = 10000;
    var set_number = set_top_number + 1;
    do{
      do{
        do{
        first_number = Math.floor(Math.random()*set_number);
	}while(first_number<1000);
        second_number = Math.floor(Math.random()*first_number+1);
        result = first_number - second_number;
      }while(result<0);
      horizontal_type = first_number + " - " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " - " + second_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 十一单元： 有余数的除法
  $("#btn_divide_have_remainder").click(function(){
    second_number = Math.floor(Math.random()*8+2);
    do{
      do{
        first_number = Math.floor(Math.random()*(second_number * 10));
        var integer_part = Math.floor(first_number/second_number);
        var remainder = first_number % second_number;
        result = integer_part.toString() + "......" + remainder.toString();
      }while(remainder == 0 || first_number < second_number);
      horizontal_type = first_number + " ÷ " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " ÷  " + second_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 十二单元：多位数乘以一位数
  //多位数乘以一位数（口算）
  $("#btn_round_many_digit_mutiple_1d").click(function(){
    do{ 
      do{ 
        var round_digits = [10, 100, 1000];
        var round_digit_id = Math.floor(Math.random()*3);
        var round_digit = parseInt(round_digits[round_digit_id]);
        first_number = Math.floor(Math.random()*10)*round_digit;
        second_number = Math.floor(Math.random()*8)+2;
        result = first_number * second_number;
      }while(result > 10000);
      horizontal_type = first_number + " × " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " ×  " + second_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  //多位数乘以一位数
  $("#btn_many_digit_mutiple_1d").click(function(){
    do{ 
      do{ 
        first_number = Math.floor(Math.random()*10001);
        second_number = Math.floor(Math.random()*10);
        result = first_number * second_number;
      }while(result > 10000);
      horizontal_type = first_number + " × " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " ×  " + second_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  //十三单元：分数的简单计算
  $("#btn_simple_fraction_add_and_subtract").click(function(){
    var operators=[" + ", " - "];
    var operator_index = Math.floor(Math.random()*operators.length);
    var operator = operators[operator_index];
    var denominator = Math.floor(Math.random()*8)+2;
    do{
      if (operator == " + "){
        var first_numerator =  Math.floor(Math.random()*(denominator-1))+1;
        var second_numerator =  Math.floor(Math.random()*(denominator-first_numerator-1))+1;
        var result_numerator = first_numerator + second_numerator;
        // 分数可视化
        transfer_fraction_result(0, result_numerator, denominator);
        first_number = "f" + "0" + "," + first_numerator.toString() + "," + denominator.toString();
        second_number = "f" + "0" + "," + second_numerator.toString() + "," + denominator.toString();
        horizontal_type = [first_number, "+", second_number, "="];
        // horizontal_type = [first_number, "+", second_number, "=", result]; //测试运算结果。
      }else{
        var first_numerator =  Math.floor(Math.random()*(denominator-1))+1;
        var second_numerator =  Math.floor(Math.random()*(first_numerator-1))+1;
        var result_numerator = first_numerator - second_numerator;
        // 分数可视化
        transfer_fraction_result(0, result_numerator, denominator);
        first_number = "f" + "0" + "," + first_numerator.toString() + "," + denominator.toString();
        second_number = "f" + "0" + "," + second_numerator.toString() + "," + denominator.toString();
        horizontal_type = [first_number, "-", second_number, "="];
        // horizontal_type = [first_number, "-", second_number, "=", result]; //测试运算结果。
      };
    }while(horizontal_type == pre_horizontal_type);
    // 转换分数格式，方便用户输入
    transfer_result_fraction_for_input();
    // 计算cavas的长度，获取字体高度，生成绘图区
    ht_length_cal();
    var font_size = $(".par").css("font-size");
    font_size = font_size.replace("px", "");
    var canvas_height = font_size*2;
    var canvas_width = Math.ceil(ht_length*canvas_height/3);
    var canvas_html = "<canvas id=\"canvas_13\" width=\"" + canvas_width + "\" height=\"" + canvas_height + "\" style=\"vertical-align: middle;\"> 您的浏览器不支持 HTML5 canvas 标签。</canvas>" 
    $("#par_unit_13").html(canvas_html);
    //$(".par").html("现在测试分数");
    // 输出横式
    draw_fraction("#canvas_13");
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  //十四单元：除数是一位数的除法
  // 口算除法
  $("#btn_round_many_digits_divide_1d").click(function(){
    do{
      do{
        var round_digits = [10, 100, 1000];
        var round_digit_id = Math.floor(Math.random()*3);
        var round_digit = parseInt(round_digits[round_digit_id]);
        first_number = Math.floor(Math.random()*10)*round_digit;
        result = (Math.floor(Math.random()*9)+1)*round_digit;
        second_number = Math.floor(Math.random()*8)+2;
        first_number = result * second_number;
      }while(first_number > 10000);
      horizontal_type = first_number + " ÷ " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " ÷ " + second_number + " = " + result; //测试运算结果。
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  // 笔算除法
  // 商中间、末尾有0的除法
  $("#btn_many_digits_with_0_divide_1d").click(function(){
    do{
      do{
        result = (Math.floor(Math.random()*10000)+1);
        second_number = Math.floor(Math.random()*8)+2;
        first_number = result * second_number;
        var has_zero = first_number.toString().indexOf("0");
      }while(first_number > 10000 || has_zero == -1);
      horizontal_type = first_number + " ÷ " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " ÷ " + second_number + " = " + result; //测试运算结果。
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  // 除法是一位数的除法
  $("#btn_many_digits_divide_1d").click(function(){
    do{
      do{
        result = (Math.floor(Math.random()*1000)+1);
        second_number = Math.floor(Math.random()*8)+2;
        first_number = result * second_number;
      }while(first_number > 10000);
      horizontal_type = first_number + " ÷ " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " ÷ " + second_number + " = " + result; //测试运算结果。
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  // 十五单元：两位数乘以两位数
  // 口算整十相乘
  $("#btn_round_tens_mutiple_round_tens").click(function(){
    do{ 
      first_number = (Math.floor(Math.random()*9)+1)*10;
      second_number = (Math.floor(Math.random()*9)+1)*10;
      result = first_number * second_number;
      horizontal_type = first_number + " × " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " ×  " + second_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  // 口算两位乘整十
  $("#btn_2_digits_mutiple_round_tens").click(function(){
    do{ 
      first_number = Math.floor(Math.random()*89)+11;
      second_number = (Math.floor(Math.random()*9)+1)*10;
      result = first_number * second_number;
      horizontal_type = first_number + " × " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " ×  " + second_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  // 笔算不进位的两位数乘两位数
  $("#btn_2_digits_mutiple_2_digits_not_carry").click(function(){
    do{ 
      first_number = Math.floor(Math.random()*90)+10;
      second_number = Math.floor(Math.random()*90)+10;
      result = first_number * second_number;
      horizontal_type = first_number + " × " + second_number + " = ";
      var carry_flag = false;
      if(parseInt(first_number.toString()[0])*parseInt(second_number.toString()[0]) > 9){carry_flag = true};
      if(parseInt(first_number.toString()[0])*parseInt(second_number.toString()[1]) > 9){carry_flag = true};
      if(parseInt(first_number.toString()[1])*parseInt(second_number.toString()[0]) > 9){carry_flag = true};
      if(parseInt(first_number.toString()[1])*parseInt(second_number.toString()[1]) > 9){carry_flag = true};
    }while(horizontal_type == pre_horizontal_type  || carry_flag == true);
    //horizontal_type = first_number + " ×  " + second_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  // 笔算两位数乘两位数
  $("#btn_2_digits_mutiple_2_digits").click(function(){
    do{ 
      first_number = Math.floor(Math.random()*100)+1;
      second_number = Math.floor(Math.random()*100)+1;
      result = first_number * second_number;
      horizontal_type = first_number + " × " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " ×  " + second_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  // 十六单元 简单小数加减法
  // 简单小数的加法
  $("#btn_simple_decimal_add").click(function(){
    do{
      do{
        first_number_ready = Math.floor(Math.random()*90)+10;
      }while(first_number_ready%10 == 0);
      first_number = first_number_ready/10;
      second_number = (Math.floor(Math.random()*90)+10)/10;
      var temp_result = first_number + second_number;
      result = temp_result.toFixed(1);
      if (result[result.length - 1] == "0"){
        result = temp_result.toFixed(0);
      };
      horizontal_type = first_number + " + " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    // horizontal_type = first_number + " + " + second_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  // 简单小数的减法
  $("#btn_simple_decimal_subtract").click(function(){
    do{
      first_number = (Math.floor(Math.random()*90)+10)/10;
      second_number = (Math.floor(Math.random()*(first_number*10))+1)/10;
      var temp_result = first_number - second_number;
      result = temp_result.toFixed(1);
      if (result[result.length - 1] == "0"){
        result = temp_result.toFixed(0);
      };
      horizontal_type = first_number + " - " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    // horizontal_type = first_number + " - " + second_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  // 十七单元：三位数乘两位数
  // 口算三位数乘整十数
  $("#btn_3_digits_mutiple_round_tens").click(function(){
    do{ 
      first_number = Math.floor(Math.random()*900)+100;
      second_number = (Math.floor(Math.random()*9)+1)*10;
      result = first_number * second_number;
      horizontal_type = first_number + " × " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " ×  " + second_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  // 竖式计算三位数乘两位数
  // 三位数乘两位数
  $("#btn_3_digits_mutiple_2_digits").click(function(){
    do{ 
      first_number = Math.floor(Math.random()*900)+100;
      second_number = Math.floor(Math.random()*90)+10;
      result = first_number * second_number;
      horizontal_type = first_number + " × " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " ×  " + second_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  // 十八单元：除数是两位数的除法
  // 口算几百几十除以整十数
  $("#btn_round_huns_tens_divide_round_tens").click(function(){
    do{
      do{
        var round_digits = [10, 100];
        var round_digit_id = Math.floor(Math.random()*2);
        var round_digit = parseInt(round_digits[round_digit_id]);
        result = (Math.floor(Math.random()*99)+1);
        second_number = (Math.floor(Math.random()*9)+1)*10;
        first_number = result * second_number;
      }while(first_number > 990);
      horizontal_type = first_number + " ÷ " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    // horizontal_type = first_number + " ÷ " + second_number + " = " + result; //测试运算结果。
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  // 笔算除法
  // 三位数整除两位数
  $("#btn_3_digits_divide_2_digits").click(function(){
    do{
      do{
        first_number = Math.floor(Math.random()*900)+100;
        second_number = Math.floor(Math.random()*90)+10;
        result = first_number / second_number;
      }while(first_number%second_number != 0);
      horizontal_type = first_number + " ÷ " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    // horizontal_type = first_number + " ÷ " + second_number + " = " + result; //测试运算结果。
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 多位数除以两位数
  $("#btn_many_digits_divide_2_digits").click(function(){
    second_number = Math.floor(Math.random()*89)+11;
    do{
      do{
        first_number = Math.floor(Math.random()*10000);
        var integer_part = Math.floor(first_number/second_number);
        var remainder = first_number % second_number;
        if(remainder == 0){
	  result = integer_part;
	}else{
          result = integer_part.toString() + "......" + remainder.toString();
	}
      }while( first_number < second_number);
      horizontal_type = first_number + " ÷ " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " ÷  " + second_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  // 十九单元：四则运算
  // 积商之和差混合（千以内）
  $("#btn_mutiple_or_divide_and_plus_or_subtract").click(function(){
    var temp_result =0;
    var operators_1=[" × ", " ÷ "];
    var operators_2=[" + ", " - "];
    var operator_index = Math.floor(Math.random()*operators_1.length);
    var operator_1 = operators_1[operator_index];
    var operator_index = Math.floor(Math.random()*operators_2.length);
    var operator_2 = operators_2[operator_index];
    do{
      if(operator_1 == " × "){
        first_number = Math.floor(Math.random()*1000);
        second_number = Math.floor(Math.random()*98)+2;
        temp_result = first_number * second_number;
      }else{
        do{
          first_number = Math.floor(Math.random()*1000);
          second_number = Math.floor(Math.random()*99)+1;
          temp_result = first_number / second_number;
        }while(first_number%second_number != 0);
      };
      third_number = Math.floor(Math.random()*1000);
      if(operator_2 == " + "){          // 处理加法
	result = temp_result + third_number;
        var pre_or_post_dicisions = [true, false];
	var pre_or_post_id = Math.floor(Math.random()*pre_or_post_dicisions.length);
        var pre_or_post = pre_or_post_dicisions[pre_or_post_id];
	if(pre_or_post == true){
          horizontal_type = third_number + operator_2 + first_number + operator_1 + second_number + " = ";
          // horizontal_type = third_number + operator_2 + first_number + operator_1 + second_number + " = " + result;
	}else{
          horizontal_type = first_number + operator_1 + second_number + operator_2 +  third_number + " = ";
          // horizontal_type = first_number + operator_1 + second_number + operator_2 +  third_number + " = " + result;
	};
      }else{                            // 处理减法
        if (third_number > temp_result){
          result = third_number - temp_result;
          horizontal_type = third_number + operator_2 + first_number + operator_1 + second_number + " = ";
          // horizontal_type = third_number + operator_2 + first_number + operator_1 + second_number + " = " + result;
	}else{
          result = temp_result - third_number;
          horizontal_type = first_number + operator_1 + second_number + operator_2 +  third_number + " = ";
          // horizontal_type = first_number + operator_1 + second_number + operator_2 +  third_number + " = " + result;
	}; 
      };
    }while(horizontal_type == pre_horizontal_type);
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 两个积商之和差混合（千以内）
  $("#btn_2_mutiple_or_divide_and_plus_or_subtract").click(function(){
    var temp_result_1 = 0;
    var temp_result_2 = 0;
    var operators_1=[" × ", " ÷ "];
    var operators_2=[" + ", " - "];
    var operator_index = Math.floor(Math.random()*operators_1.length);
    var operator_1 = operators_1[operator_index];
    var operator_index = Math.floor(Math.random()*operators_2.length);
    var operator_2 = operators_2[operator_index];
    var operator_index = Math.floor(Math.random()*operators_1.length);
    var operator_3 = operators_1[operator_index];
    do{
      if(operator_1 == " × "){
        first_number = Math.floor(Math.random()*1000);
        second_number = Math.floor(Math.random()*98)+2;
        temp_result_1 = first_number * second_number;
      }else{
        do{
          first_number = Math.floor(Math.random()*1000);
          second_number = Math.floor(Math.random()*99)+1;
          temp_result_1 = first_number / second_number;
        }while(first_number%second_number != 0);
      };
      if(operator_3 == " × "){
        third_number = Math.floor(Math.random()*1000);
        fourth_number = Math.floor(Math.random()*98)+2;
        temp_result_2 = third_number * fourth_number;
      }else{
        do{
          third_number = Math.floor(Math.random()*1000);
          fourth_number = Math.floor(Math.random()*99)+1;
          temp_result_2 = third_number / fourth_number;
        }while(third_number%fourth_number != 0);
      };
      if(operator_2 == " + "){          // 处理加法
        result = temp_result_1 + temp_result_2;
	horizontal_type = first_number + operator_1 + second_number + operator_2 + third_number + operator_3 + fourth_number + equals_sign;
      }else{
        if (temp_result_1 > temp_result_2){
          result = temp_result_1 - temp_result_2;
	  horizontal_type = first_number + operator_1 + second_number + operator_2 + third_number + operator_3 + fourth_number + equals_sign;
	}else{
          result = temp_result_2 - temp_result_1;
	  horizontal_type = third_number + operator_3 + fourth_number + operator_2 + first_number + operator_1 + second_number + equals_sign;
	}; 
      };
    }while(horizontal_type == pre_horizontal_type);
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 含括号三步计算
  $("#btn_3_step_with_brackets").click(function(){
    // 随机产生运算符
    function operator(operators){
      var operators_index = Math.floor(Math.random()*operators.length);
      var operator = operators[operators_index];
      return operator;
    };
    // 生成加数
    function addend(addend_1, result_start, result_top){
      var sum_start = 2;
      var sum_top = 10000;
      // 已知加数大于约定和的上限
      if(addend_1 >= sum_top){faile_flag = true;return false};
      // 已知加数为负数
      if(addend_1 < 0){faile_flag = true;return false};
      do{
      var addend = Math.floor(Math.random()*(sum_top - addend_1 - sum_start))+sum_start;
      }while(addend < result_start || addend > result_top);
      return addend;
    };
    // 生成被减数
    function minuend(subtrahend, result_start, result_top){
      var difference_start = 0;
      var difference_top = result_top - result_start;
      // 已知减数大于未知被减数的最大值
      if(subtrahend >= result_top){faile_flag = true;return false};
      // 已知减数为负数
      if(subtrahend < 0){faile_flag = true;return false};
      do{
        var minuend =  Math.floor(Math.random()*(subtrahend + difference_top - subtrahend))+subtrahend;
      }while(minuend < result_start || minuend > result_top);
      return minuend;
    };
    // 生成减数
    function subtrahend(minuend, result_start, result_top){
      var difference_start = 0;
      var difference_top = 10000;
      // 已知被减数太大（和未知减数的差超过上限）
      if(minuend - result_top > difference_top){faile_flag = true; return false;}
      // 已知被减数太小（和未知减数的差超过上限）
      if(minuend < result_start+1){faile_flag = true; return false;}
      do{
        var subtrahend = Math.floor(Math.random()*(minuend - result_start))+result_start;
      }while(subtrahend < result_start || subtrahend > result_top);
      return subtrahend;
    };
    // 生成乘数
    function multiplier (multiplier_1, result_start, result_top){
      var product_start = 2;
      var product_top = 1000000;
      // 已知乘数为0或负数
      if(multiplier_1 <= 0){faile_flag = true ;return false; };
      // 已知乘数太大（最大积除以已知乘数的商小于未知乘数的约定最小值）
      if(product_top/multiplier_1 < result_start){faile_flag = true; return false; };
      do{
        var multiplier = Math.floor(Math.random()*result_top - result_start)+result_start;
      }while(multiplier < result_start || multiplier > result_top);
      return multiplier;
    };
    // 生成被除数
    function dividend(divisor, result_start, result_top){
      var quotient_start = 2;
      var quotient_top = 100;
      // 已知除数大于教学范围100
      if(divisor>100){faile_flag = true; return false;}
      // 已知除数小于等于0
      if(divisor<=0){faile_flag = true; return false;}
      do{
        var dividend = (Math.floor(Math.random()*quotient_top - quotient_start)+quotient_start) * divisor;
      }while(dividend < result_start || dividend > result_top);
      return dividend;
    };
    // 生成除数
    function divisor(dividend, result_start, result_top){
      var quotient_start = 2;
      var quotient_top = 100;
      // 被除数太小（小于约定最小商数和除数最小值的积）
      if(dividend < quotient_start*result_start){faile_flag = true;return false};
      // 被除数大于指定商最大值和除数最大值的积
      if(dividend > quotient_top*result_top){faile_flag = true;return false};
      var try_times=1;
      do{
        var divisor = Math.floor(Math.random()*(dividend / quotient_start - quotient_start))+quotient_start;
	try_times++;
        if(try_times == 100){faile_flag = true; return false; break; };
      }while( dividend%divisor != 0 );
      return divisor;
    };
    do{
    // 第一步是选择括号的五种位置。
    var brackets_positions = [1, 2, 3, 4, 5];
    var brackets_position_index = Math.floor(Math.random()*brackets_positions.length);
    var brackets_position = brackets_positions[brackets_position_index];
    //alert(brackets_position);
    switch (brackets_position)
    {
    case 1:    // 第一种：(a b) c d
      do{
        var faile_flag = false;
        first_number = Math.floor(Math.random()*(1000-1))+1;
        operator_1 = operator(["+", "-"]);
        operator_2 = operator(["*", "/"]);
        operator_3 = operator(["+", "-", "*", "/"]);
        // var operator_msg =brackets_position + operator_1 + operator_2 + operator_3;
        // alert(operator_msg);
        switch (operator_1)
	{
	  case "+":
	    second_number = addend(first_number, 1, 1000);
	    temp_result_1 = first_number + second_number;
            //alert(temp_result_1);
	    break;
	  case "-":
	    second_number = subtrahend(first_number, 1, 1000);
	    temp_result_1 = first_number - second_number;
            //alert(temp_result_1);
	    break;
	};
        switch (operator_2)
	{
	  case "*":
	    third_number = multiplier(temp_result_1, 2, 1000);
	    temp_result_2 = temp_result_1 * third_number;
            //alert(temp_result_2);
	    break;
	  case "/":
	    third_number = divisor(temp_result_1, 2, 1000);
	    temp_result_2 = temp_result_1 / third_number;
            //alert(temp_result_2);
	    break;
	};
        switch (operator_3)
	{
	  case "+":
	    fourth_number = addend(temp_result_2, 1, 1000);
	    result = temp_result_2 + fourth_number;
	    break;
	  case "-":
	    fourth_number = subtrahend(temp_result_2, 1, 1000);
	    result = temp_result_2 - fourth_number;
	    break;
	  case "*":
	    fourth_number = multiplier(temp_result_2, 2, 10000);
	    result = temp_result_2 * fourth_number;
	    break;
	  case "/":
	    fourth_number = divisor(temp_result_2, 2, 1000);
	    result = temp_result_2 / fourth_number;
	    break;
	};
      }while(result > 1000000 || result < 0 || faile_flag == true);
      horizontal_type = "(" + first_number + operator_1 + second_number + ")" + operator_2 + third_number + operator_3 + fourth_number + " = ";
      // horizontal_type = "(" + first_number + operator_1 + second_number + ")" + operator_2 + third_number + operator_3 + fourth_number + " = " + result;
      horizontal_type = horizontal_type.replace("*", "×");
      horizontal_type = horizontal_type.replace(/\//g, "÷");
      break;
    case 2:    // 第二种： (a b c) d
      do{
        var faile_flag = false;
        do{
          operator_1 = operator(["+", "-", "*", "/"]);
          operator_2 = operator(["+", "-", "*", "/"]);
          operator_3 = operator(["*", "/"]);
          var brackets_inner_eq_outer = false;
	  var priority_1 = ["*", "/"].indexOf(operator_1);
	  var priority_2 = ["*", "/"].indexOf(operator_2);
	  if(priority_1 != -1 && priority_2 != -1){brackets_inner_eq_outer = true};
	}while(brackets_inner_eq_outer == true);
        // var operator_msg =brackets_position + operator_1 + operator_2 + operator_3;
        // alert(operator_msg);
	priority_1 = ["+", "-"].indexOf(operator_1);
	priority_2 = ["*", "/"].indexOf(operator_2);
	if (priority_1 != -1 && priority_2 != -1){
        second_number = Math.floor(Math.random()*(1000-1))+1;
        switch (operator_2)
	{
	  case "+":
	    third_number = addend(second_number, 1, 1000);
	    temp_result_1 = second_number + third_number;
            //alert(temp_result_1);
	    break;
	  case "-":
	    third_number = subtrahend(second_number, 1, 1000);
	    temp_result_1 = second_number - third_number;
            //alert(temp_result_1);
	    break;
	  case "*":
	    third_number = multiplier(second_number, 2, 1000);
	    temp_result_1 = second_number * third_number;
            //alert(temp_result_1);
	    break;
	  case "/":
	    third_number = divisor(second_number, 2, 1000);
	    temp_result_1 = second_number / third_number;
            //alert(temp_result_1);
	    break;
	};
        switch (operator_1)
	{
	  case "+":
	    first_number = addend(temp_result_1, 1, 1000);
	    temp_result_2 = first_number + temp_result_1;
            //alert(temp_result_2);
	    break;
	  case "-":
	    first_number = minuend(temp_result_1, 1, 1000);
	    temp_result_2 = first_number - temp_result_1
            //alert(temp_result_2);
	    break;
	  case "*":
	    first_number = multiplier(temp_result_1, 2, 1000);
	    temp_result_2 = first_number * temp_result_1;
            //alert(temp_result_2);
	    break;
	  case "/":
	    first_number = dividend(temp_result_1, 2, 10000);
	    temp_result_2 = first_number / temp_result_1;
            //alert(temp_result_2);
	    break;
	};
	}else{
        first_number = Math.floor(Math.random()*(1000-1))+1;
        switch (operator_1)
	{
	  case "+":
	    second_number = addend(first_number, 1, 1000);
	    temp_result_1 = first_number + second_number;
            //alert(temp_result_1);
	    break;
	  case "-":
	    second_number = subtrahend(first_number, 1, 1000);
	    temp_result_1 = first_number - second_number;
            //alert(temp_result_1);
	    break;
	  case "*":
	    second_number = multiplier(first_number, 2, 10000);
	    temp_result_1 = first_number * second_number;
            //alert(temp_result_1);
	    break;
	  case "/":
	    second_number = divisor(first_number, 2, 10000);
	    temp_result_1 = first_number / second_number;
            //alert(temp_result_1);
	    break;
	};
        switch (operator_2)
	{
	  case "+":
	    third_number = addend(temp_result_1, 1, 1000);
            temp_result_2 = temp_result_1 + third_number;
            //alert(temp_result_2);
	    break;
	  case "-":
	    third_number = subtrahend(temp_result_1, 1, 1000);
            temp_result_2 = temp_result_1 - third_number;
            //alert(temp_result_2);
	    break;
	  case "*":
	    third_number = multiplier(temp_result_1, 2, 1000);
            temp_result_2 = temp_result_1 * third_number;
            //alert(temp_result_2);
	    break;
	  case "/":
	    third_number = divisor(temp_result_1, 2, 1000);
            temp_result_2 = temp_result_1 / third_number;
            //alert(temp_result_2);
	    break;
	};
	};
        switch (operator_3)
	{
	  case "*":
	    fourth_number = multiplier(temp_result_2, 2, 1000);
            result = temp_result_2 * fourth_number;
	    break;
	  case "/":
	    fourth_number = divisor(temp_result_2, 2, 100);
            result = temp_result_2 / fourth_number;
	    break;
	};
      }while(result > 1000000  || result < 0 || faile_flag == true);
      horizontal_type = "(" + first_number + operator_1 + second_number + operator_2 + third_number + ")" + operator_3 + fourth_number + " = ";
      // horizontal_type = "(" + first_number + operator_1 + second_number + operator_2 + third_number + ")" + operator_3 + fourth_number + " = " + result;
      horizontal_type = horizontal_type.replace("*", "×");
      horizontal_type = horizontal_type.replace(/\//g, "÷");
      break;
    case 3:    // 第三种： a (b c) d
      do{
        var faile_flag = false;
        do{
          operator_1 = operator(["+", "-", "*", "/"]);
          operator_2 = operator(["+", "-", "*", "/"]);
          operator_3 = operator(["+", "-", "*", "/"]);
	  var need_no_brackets = false;
	  if(operator_1 == "+" && operator_2 == "+" && operator_3 == "+"){need_no_brackets = true;};
	  if(operator_1 == "+" && operator_2 == "+" && operator_3 == "-"){need_no_brackets = true;};
	  if(operator_1 == "+" && operator_2 == "-" && operator_3 == "-"){need_no_brackets = true;};
	  if(operator_1 == "+" && operator_2 == "-" && operator_3 == "+"){need_no_brackets = true;};
	  if(operator_1 == "*" && operator_2 == "*" && operator_3 == "*"){need_no_brackets = true;};
	  if(operator_1 == "*" && operator_2 == "*" && operator_3 == "/"){need_no_brackets = true;};
	  if(operator_1 == "*" && operator_2 == "/" && operator_3 == "/"){need_no_brackets = true;};
	  if(operator_1 == "*" && operator_2 == "/" && operator_3 == "*"){need_no_brackets = true;};
	  var priority_1 = ["+", "-"].indexOf(operator_1);
	  var priority_2 = ["*", "/"].indexOf(operator_2);
	  var priority_3 = ["+", "-"].indexOf(operator_3);
	  if(priority_1 != -1 && priority_2 != -1 && priority_3 != -1){need_no_brackets = true};

	}while(need_no_brackets == true);
        // var operator_msg =brackets_position + operator_1 + operator_2 + operator_3;
        // alert(operator_msg);
        second_number = Math.floor(Math.random()*(1000-1))+1;
        switch (operator_2)
	{
	  case "+":
	    third_number = addend(second_number, 1, 1000);
            temp_result_1 = second_number + third_number;
            //alert(temp_result_1);
	    break;
	  case "-":
	    third_number = subtrahend(second_number, 1, 1000);
            temp_result_1 = second_number - third_number;
            //alert(temp_result_1);
	    break;
	  case "*":
	    third_number = multiplier(second_number, 2, 1000);
            temp_result_1 = second_number * third_number;
            //alert(temp_result_1);
	    break;
	  case "/":
	    third_number = divisor(second_number, 2, 1000);
            temp_result_1 = second_number / third_number;
            //alert(temp_result_1);
	    break;
	};
	priority_1 = ["+", "-"].indexOf(operator_1);
	priority_2 = ["*", "/"].indexOf(operator_3);
	if (priority_1 != -1 && priority_2 != -1){
        switch (operator_3)
	{
	  case "+":
	    fourth_number = addend(temp_result_1, 1, 1000);
            temp_result_2 =  temp_result_1 + fourth_number;
            //alert(temp_result_2);
	    break;
	  case "-":
	    fourth_number = subtrahend(temp_result_1, 1, 1000);
            temp_result_2 =  temp_result_1 - fourth_number;
            //alert(temp_result_2);
	    break;
	  case "*":
	    fourth_number = multiplier(temp_result_1, 2, 1000);
            temp_result_2 =  temp_result_1 * fourth_number;
            //alert(temp_result_2);
	    break;
	  case "/":
	    fourth_number = divisor(temp_result_1, 2, 1000);
            temp_result_2 =  temp_result_1 / fourth_number;
            //alert(temp_result_2);
	    break;
	};
        switch (operator_1)
	{
	  case "+":
	    first_number = addend(temp_result_2, 1, 1000);
            result = first_number + temp_result_2;
	    break;
	  case "-":
	    first_number = minuend(temp_result_2, 1, 1000);
            result = first_number - temp_result_2;
	    break;
	  case "*":
	    first_number = multiplier(temp_result_2, 2, 1000);
            result = first_number * temp_result_2;
	    break;
	  case "/":
	    first_number = dividend(temp_result_2, 2, 10000);
            result = first_number / temp_result_2;
	    break;
	};
	}else{
        switch (operator_1)
	{
	  case "+":
	    first_number = addend(temp_result_1, 1, 1000);
            temp_result_2 = first_number + temp_result_1;
            //alert(temp_result_2);
	    break;
	  case "-":
	    first_number = minuend(temp_result_1, 1, 1000);
            temp_result_2 = first_number - temp_result_1;
            //alert(temp_result_2);
	    break;
	  case "*":
	    first_number = multiplier(temp_result_1, 2, 1000);
            temp_result_2 = first_number * temp_result_1;
            //alert(temp_result_2);
	    break;
	  case "/":
	    first_number = dividend(temp_result_1, 2, 10000);
            temp_result_2 = first_number / temp_result_1;
            //alert(temp_result_2);
	    break;
	};
        switch (operator_3)
	{
	  case "+":
	    fourth_number = addend(temp_result_2, 1, 1000);
            result = fourth_number + temp_result_2;
	    break;
	  case "-":
	    fourth_number = subtrahend(temp_result_2, 1, 1000);
            result = temp_result_2 - fourth_number;
	    break;
	  case "*":
	    fourth_number = multiplier(temp_result_2, 2, 1000);
            result = fourth_number * temp_result_2;
	    break;
	  case "/":
	    fourth_number = divisor(temp_result_2, 2, 1000);
            result = temp_result_2 / fourth_number;
	    break;
	};
        };
      }while(result > 1000000  || result < 0 || faile_flag == true);
      horizontal_type = first_number + operator_1 + "(" + second_number + operator_2 + third_number + ")" + operator_3 + fourth_number + " = ";
      //horizontal_type = first_number + operator_1 + "(" + second_number + operator_2 + third_number + ")" + operator_3 + fourth_number + " = " + result;
      horizontal_type = horizontal_type.replace("*", "×");
      horizontal_type = horizontal_type.replace(/\//g, "÷");
      break;
    case 4:    // 第四种： a (b c d)
      do{
        var faile_flag = false;
        do{
          operator_1 = operator(["-", "*", "/"]);
          operator_2 = operator(["+", "-", "*", "/"]);
          operator_3 = operator(["+", "-", "*", "/"]);
	  var need_no_brackets = false;
	  if(operator_1 == "*" && operator_2 == "*" && operator_3 == "*"){need_no_brackets = true;};
	  if(operator_1 == "*" && operator_2 == "/" && operator_3 == "*"){need_no_brackets = true;};
	  if(operator_1 == "*" && operator_2 == "/" && operator_3 == "/"){need_no_brackets = true;};
	  if(operator_1 == "*" && operator_2 == "*" && operator_3 == "/"){need_no_brackets = true;};
	  var priority_1 = ["+", "-"].indexOf(operator_1);
	  var priority_2 = ["*", "/"].indexOf(operator_2);
	  var priority_3 = ["*", "/"].indexOf(operator_3);
	  if(priority_1 != -1 && priority_2 != -1 && priority_3 != -1){need_no_brackets = true};
	}while(need_no_brackets == true);
        // var operator_msg =brackets_position + operator_1 + operator_2 + operator_3;
        // alert(operator_msg);
        third_number = Math.floor(Math.random()*(1000-1))+1;
	priority_1 = ["+", "-"].indexOf(operator_2);
	priority_2 = ["*", "/"].indexOf(operator_3);
	if (priority_1 != -1 && priority_2 != -1){
        switch (operator_3)
	{
	  case "+":
	    fourth_number = addend(third_number, 1, 1000);
            temp_result_1 =  third_number + fourth_number;
            //alert(temp_result_1);
	    break;
	  case "-":
	    fourth_number = subtrahend(third_number, 1, 1000);
            temp_result_1 =  third_number - fourth_number;
            //alert(temp_result_1);
	    break;
	  case "*":
	    fourth_number = multiplier(third_number, 2, 1000);
            temp_result_1 =  third_number * fourth_number;
            //alert(temp_result_1);
	    break;
	  case "/":
	    fourth_number = divisor(third_number, 2, 1000);
            temp_result_1 =  third_number / fourth_number;
            //alert(temp_result_1);
	    break;
	};
        switch (operator_2)
	{
	  case "+":
	    second_number = addend(temp_result_1, 1, 1000);
            temp_result_2 = second_number + temp_result_1;
            //alert(temp_result_2);
	    break;
	  case "-":
	    second_number = minuend(temp_result_1, 1, 1000);
            temp_result_2 = second_number - temp_result_1;
            //alert(temp_result_2);
	    break;
	  case "*":
	    second_number = multiplier(temp_result_1, 2, 1000);
            temp_result_2 = second_number * temp_result_1;
            //alert(temp_result_2);
	    break;
	  case "/":
	    second_number = dividend(temp_result_1, 2, 10000);
            temp_result_2 = second_number / temp_result_1;
            //alert(temp_result_2);
	    break;
	};
	}else{
        switch (operator_2)
	{
	  case "+":
	    second_number = addend(third_number, 1, 1000);
            temp_result_1 = second_number + third_number;
            //alert(temp_result_1);
	    break;
	  case "-":
	    second_number = minuend(third_number, 1, 1000);
            temp_result_1 = second_number - third_number;
            //alert(temp_result_1);
	    break;
	  case "*":
	    second_number = multiplier(third_number, 2, 1000);
            temp_result_1 = second_number * third_number;
            //alert(temp_result_1);
	    break;
	  case "/":
	    second_number = dividend(third_number, 2, 10000);
            temp_result_1 = second_number / third_number;
            //alert(temp_result_1);
	    break;
	};
        switch (operator_3)
	{
	  case "+":
	    fourth_number = addend(temp_result_1, 1, 1000);
            temp_result_2 = fourth_number + temp_result_1;
            //alert(temp_result_2);
	    break;
	  case "-":
	    fourth_number = subtrahend(temp_result_1, 1, 1000);
            temp_result_2 = temp_result_1 - fourth_number;
            //alert(temp_result_2);
	    break;
	  case "*":
	    fourth_number = multiplier(temp_result_1, 2, 1000);
            temp_result_2 = fourth_number * temp_result_1;
            //alert(temp_result_2);
	    break;
	  case "/":
	    fourth_number = divisor(temp_result_1, 2, 1000);
            temp_result_2 = temp_result_1 / fourth_number;
            //alert(temp_result_2);
	    break;
	};
        };
        switch (operator_1)
	{
	  case "+":
	    first_number = addend(temp_result_2, 1, 1000);
            result = first_number + temp_result_2;
	    break;
	  case "-":
	    first_number = minuend(temp_result_2, 1, 1000);
            result = first_number - temp_result_2;
	    break;
	  case "*":
	    first_number = multiplier(temp_result_2, 2, 1000);
            result = first_number * temp_result_2;
	    break;
	  case "/":
	    first_number = dividend(temp_result_2, 2, 10000);
            result = first_number / temp_result_2;
	    break;
	};
      }while(result > 1000000  || result < 0 || faile_flag == true);
      horizontal_type = first_number + operator_1 + "(" + second_number + operator_2 + third_number + operator_3 + fourth_number + ")" + " = ";
      //horizontal_type = first_number + operator_1 + "(" + second_number + operator_2 + third_number + operator_3 + fourth_number + ")" + " = " + result;
      horizontal_type = horizontal_type.replace("*", "×");
      horizontal_type = horizontal_type.replace(/\//g, "÷");
      break;
    case 5:    // 第五种： a b (c d)
      do{
        var faile_flag = false;
        do{
          operator_1 = operator(["+", "-", "*", "/"]);
          operator_2 = operator(["+", "-", "*", "/"]);
          operator_3 = operator(["+", "-", "*", "/"]);
	  var need_no_brackets = false;
	  if(operator_2 == "+" && operator_3 == "+"){need_no_brackets = true;};
	  if(operator_2 == "+" && operator_3 == "-"){need_no_brackets = true;};
	  if(operator_2 == "*" && operator_3 == "*"){need_no_brackets = true;};
	  if(operator_2 == "*" && operator_3 == "/"){need_no_brackets = true;};
	  var priority_2 = ["+", "-"].indexOf(operator_2);
	  var priority_3 = ["*", "/"].indexOf(operator_3);
	  if(priority_2 != -1 && priority_3 != -1){need_no_brackets = true};
	}while(need_no_brackets == true);
        // var operator_msg =brackets_position + operator_1 + operator_2 + operator_3;
        // alert(operator_msg);
        third_number = Math.floor(Math.random()*(1000-1))+1;
        switch (operator_3)
	{
	  case "+":
	    fourth_number = addend(third_number, 1, 1000);
            temp_result_1 =  third_number + fourth_number;
            //alert(temp_result_1);
	    break;
	  case "-":
	    fourth_number = subtrahend(third_number, 1, 1000);
            temp_result_1 =  third_number - fourth_number;
            //alert(temp_result_1);
	    break;
	  case "*":
	    fourth_number = multiplier(third_number, 2, 1000);
            temp_result_1 =  third_number * fourth_number;
            //alert(temp_result_1);
	    break;
	  case "/":
	    fourth_number = divisor(third_number, 2, 1000);
            temp_result_1 =  third_number / fourth_number;
            //alert(temp_result_1);
	    break;
	};
	priority_1 = ["+", "-"].indexOf(operator_1);
	priority_2 = ["*", "/"].indexOf(operator_2);
	if (priority_1 != -1 && priority_2 != -1){
        switch (operator_2)
	{
	  case "+":
	    second_number = addend(temp_result_1, 1, 1000);
            temp_result_2 = second_number + temp_result_1;
	    break;
	  case "-":
	    second_number = minuend(temp_result_1, 1, 1000);
            temp_result_2 = second_number - temp_result_1;
	    break;
	  case "*":
	    second_number = multiplier(temp_result_1, 2, 1000);
            temp_result_2 = second_number * temp_result_1;
	    break;
	  case "/":
	    second_number = dividend(temp_result_1, 2, 10000);
            temp_result_2 = second_number / temp_result_1;
	    break;
	};
        switch (operator_1)
	{
	  case "+":
	    first_number = addend(temp_result_2, 1, 1000);
            result = first_number + temp_result_2;
	    break;
	  case "-":
	    first_number = minuend(temp_result_2, 1, 1000);
            result = first_number - temp_result_2;
	    break;
	  case "*":
	    first_number = multiplier(temp_result_2, 2, 1000);
            result = first_number * temp_result_2;
	    break;
	  case "/":
	    first_number = dividend(temp_result_2, 2, 10000);
            result = first_number / temp_result_2;
	    break;
	};
	}else{
        first_number = Math.floor(Math.random()*(1000-1))+1;
        switch (operator_1)
	{
	  case "+":
	    second_number = addend(first_number, 1, 1000);
	    temp_result_2 = first_number + second_number;
            //alert(temp_result_2);
	    break;
	  case "-":
	    second_number = subtrahend(first_number, 1, 1000);
	    temp_result_2 = first_number - second_number;
            //alert(temp_result_2);
	    break;
	  case "*":
	    second_number = multiplier(first_number, 2, 1000);
	    temp_result_2 = first_number * second_number;
            //alert(temp_result_2);
	    break;
	  case "/":
	    second_number = divisor(first_number, 2, 1000);
	    temp_result_2 = first_number / second_number;
            //alert(temp_result_2);
	    break;
	};
        switch (operator_2)
	{
	  case "+":
            result = temp_result_2 + temp_result_1;
	    break;
	  case "-":
            result = temp_result_2 - temp_result_1;
	    break;
	  case "*":
            result = temp_result_2 * temp_result_1;
	    break;
	  case "/":
            result = temp_result_2 / temp_result_1;
            if(temp_result_2%temp_result_1 != 0){faile_flag = true;}
	    break;
	};
        };
      }while(result > 1000000  || result < 0 || faile_flag == true);
      horizontal_type = first_number + operator_1 + second_number + operator_2 + "(" + third_number + operator_3 + fourth_number + ")" + " = ";
      // horizontal_type = first_number + operator_1 + second_number + operator_2 + "(" + third_number + operator_3 + fourth_number + ")" + " = " + result;
      horizontal_type = horizontal_type.replace("*", "×");
      horizontal_type = horizontal_type.replace(/\//g, "÷");
      break;
    };
    }while(horizontal_type == pre_horizontal_type);
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 二十单元： 运算定律和简便计算
  //加法交换律
  $("#btn_commutative_law_for_addtion").click(function(){
   do{
   var blank_num = Math.floor(Math.random()*2)+1;
   if(blank_num == 1){      // 只填一个空
     var temp_result = (Math.floor(Math.random()*90)+10)*10;
     first_number = Math.floor(Math.random()*temp_result-1)+1
     second_number = temp_result - first_number;
     var chooses=[1, 2, 3, 4];
     var chooses_index = Math.floor(Math.random()*chooses.length);
     var choose = chooses[chooses_index];
     switch(choose)
     {
      case 1:
         horizontal_type = first_number + plus_sign + blank + equals_sign + second_number + plus_sign + first_number;
         result = second_number;
       break;
       case 2:
         horizontal_type = blank + plus_sign + second_number + equals_sign + second_number + plus_sign + first_number;
         result = first_number;
       break;
       case 3:
         horizontal_type = first_number + plus_sign + second_number + equals_sign + second_number + plus_sign + blank;
         result = first_number;
       break;
       case 4:
         horizontal_type = first_number + plus_sign + second_number + equals_sign + blank + plus_sign + first_number;
         result = second_number;
       break;
     }
   }else{                // 填两个空
     var temp_result = (Math.floor(Math.random()*9)+1)*10;
     first_number = Math.floor(Math.random()*temp_result-1)+1
     second_number = temp_result - first_number;
     var chooses=[1, 2, 3, 4];
     var chooses_index = Math.floor(Math.random()*chooses.length);
     var choose = chooses[chooses_index];
     switch(choose)
     {
      case 1:
         horizontal_type = first_number + plus_sign + second_number + equals_sign + blank + plus_sign + blank;
         result = second_number + " " + first_number;
       break;
       case 2:
         horizontal_type = blank + plus_sign + blank + equals_sign + first_number + plus_sign + second_number;
         result = second_number + " " + first_number;
       break;
       case 3:
         horizontal_type = blank + plus_sign + second_number + equals_sign + blank + plus_sign + first_number;
         result = first_number + " " + second_number;
       break;
       case 4:
         horizontal_type = first_number + plus_sign + blank + equals_sign + second_number + plus_sign + blank;
         result = second_number + " " + first_number;
       break;
     }
   };
    }while(horizontal_type == pre_horizontal_type);
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  //加法结合律
  $("#btn_associative_law_for_addition").click(function(){
    do{
      var temp_result = (Math.floor(Math.random()*9)+1)*100;
      first_number = Math.floor(Math.random()*999)+1;
      second_number = Math.floor(Math.random()*temp_result-1)+1
      third_number = temp_result - second_number;
      var chooses=[1, 2, 3, 4, 5, 6];
      var chooses_index = Math.floor(Math.random()*chooses.length);
      var choose = chooses[chooses_index];
      switch(choose)
      {
      case 1:
         horizontal_type = first_number + plus_sign + second_number + plus_sign + third_number + equals_sign + blank + plus_sign + "(" + second_number + plus_sign + third_number + ")";
         result = first_number;
      break;
      case 2:
         horizontal_type = first_number + plus_sign + second_number + plus_sign + third_number + equals_sign + first_number + plus_sign + "(" + blank + plus_sign + third_number + ")";
         result = second_number;
      break;
      case 3:
         horizontal_type = first_number + plus_sign + second_number + plus_sign + third_number + equals_sign + first_number + plus_sign + "(" + second_number + plus_sign + blank + ")";
         result = third_number;
      break;
      case 4:
         horizontal_type = blank + plus_sign + second_number + plus_sign + third_number + equals_sign + first_number + plus_sign + "(" + second_number + plus_sign + third_number + ")";
         result = first_number;
      break;
      case 5:
         horizontal_type = first_number + plus_sign + blank + plus_sign + third_number + equals_sign + first_number + plus_sign + "(" + second_number + plus_sign + third_number + ")";
         result = second_number;
      break;
      case 6:
         horizontal_type = first_number + plus_sign + second_number + plus_sign + blank + equals_sign + first_number + plus_sign + "(" + second_number + plus_sign + third_number + ")";
         result = third_number;
      break;
      }
    }while(horizontal_type == pre_horizontal_type);
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  
  //加法运算定律的应用（三个加数）
  $("#btn_use_addition_laws_3_addend").click(function(){
    do{
      var temp_result_1 = (Math.floor(Math.random()*9)+1)*100;
      var temp_result_2 = Math.floor(Math.random()*999)+1;
      first_number = Math.floor(Math.random()*temp_result_1-1)+1;
      second_number = temp_result_1 - first_number;
      result = temp_result_1 + temp_result_2;
      var shuffle_num=[temp_result_2, first_number, second_number];
      for(var j, x, i = shuffle_num.length;
        i; 
	j = parseInt(Math.random() * i), 
	x = shuffle_num[--i], 
	shuffle_num[i] = shuffle_num[j], 
	shuffle_num[j] = x);
      horizontal_type = shuffle_num[0] + plus_sign + shuffle_num[1] + plus_sign + shuffle_num[2] + equals_sign;
    }while(horizontal_type == pre_horizontal_type);
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  //加法运算定律的应用（四个加数）
  $("#btn_use_addition_laws_4_addend").click(function(){
    do{
      var temp_result_1 = (Math.floor(Math.random()*9)+1)*100;
      var temp_result_2 = (Math.floor(Math.random()*9)+1)*100;
      first_number = Math.floor(Math.random()*temp_result_1-1)+1;
      second_number = temp_result_1 - first_number;
      third_number = Math.floor(Math.random()*temp_result_2-1)+1;
      fourth_number = temp_result_2 - third_number;
      result = temp_result_1 + temp_result_2;
      var shuffle_num=[first_number, second_number, third_number, fourth_number];
      for(var j, x, i = shuffle_num.length;
        i; 
	j = parseInt(Math.random() * i), 
	x = shuffle_num[--i], 
	shuffle_num[i] = shuffle_num[j], 
	shuffle_num[j] = x);
      horizontal_type = shuffle_num[0] + plus_sign + shuffle_num[1] + plus_sign + shuffle_num[2] + plus_sign + shuffle_num[3] + equals_sign;
    }while(horizontal_type == pre_horizontal_type);
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 乘法交换律
  $("#btn_commutative_law_for_multiplication").click(function(){
   do{
   var blank_num = Math.floor(Math.random()*2)+1;
   if(blank_num == 1){      // 只填一个空
     var temp_result = (Math.floor(Math.random()*90)+10)*10;
     do{
       first_number = Math.floor(Math.random()*(temp_result-2))+2;
     }while(temp_result%first_number != 0);
     second_number = temp_result / first_number;
     var chooses=[1, 2, 3, 4];
     var chooses_index = Math.floor(Math.random()*chooses.length);
     var choose = chooses[chooses_index];
     switch(choose)
     {
      case 1:
         horizontal_type = first_number + times_sign + blank + equals_sign + second_number + times_sign + first_number;
         result = second_number;
       break;
       case 2:
         horizontal_type = blank + times_sign + second_number + equals_sign + second_number + times_sign + first_number;
         result = first_number;
       break;
       case 3:
         horizontal_type = first_number + times_sign + second_number + equals_sign + second_number + times_sign + blank;
         result = first_number;
       break;
       case 4:
         horizontal_type = first_number + times_sign + second_number + equals_sign + blank + times_sign + first_number;
         result = second_number;
       break;
     }
   }else{                // 填两个空
     var temp_result = (Math.floor(Math.random()*90)+10)*10;
     do{
       first_number = Math.floor(Math.random()*(temp_result-2))+2;
     }while(temp_result%first_number != 0);
     second_number = temp_result / first_number;
     var chooses=[1, 2, 3, 4];
     var chooses_index = Math.floor(Math.random()*chooses.length);
     var choose = chooses[chooses_index];
     switch(choose)
     {
      case 1:
         horizontal_type = first_number + times_sign + second_number + equals_sign + blank + times_sign + blank;
         result = second_number + " " + first_number;
       break;
       case 2:
         horizontal_type = blank + times_sign + blank + equals_sign + first_number + times_sign + second_number;
         result = second_number + " " + first_number;
       break;
       case 3:
         horizontal_type = blank + times_sign + second_number + equals_sign + blank + times_sign + first_number;
         result = first_number + " " + second_number;
       break;
       case 4:
         horizontal_type = first_number + times_sign + blank + equals_sign + second_number + times_sign + blank;
         result = second_number + " " + first_number;
       break;
     }
   };
    }while(horizontal_type == pre_horizontal_type);
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 乘法结合律
  $("#btn_associative_law_for_multiplication").click(function(){
    do{
      var temp_result = (Math.floor(Math.random()*9)+1)*100;
      first_number = Math.floor(Math.random()*99)+1;
      do{
        second_number = Math.floor(Math.random()*(temp_result-2))+2;
      }while(temp_result%second_number != 0);
      third_number = temp_result / second_number;
      var chooses=[1, 2, 3, 4, 5, 6];
      var chooses_index = Math.floor(Math.random()*chooses.length);
      var choose = chooses[chooses_index];
      switch(choose)
      {
      case 1:
         horizontal_type = first_number + times_sign + second_number + times_sign + third_number + equals_sign + blank + times_sign + "(" + second_number + times_sign + third_number + ")";
         result = first_number;
      break;
      case 2:
         horizontal_type = first_number + times_sign + second_number + times_sign + third_number + equals_sign + first_number + times_sign + "(" + blank + times_sign + third_number + ")";
         result = second_number;
      break;
      case 3:
         horizontal_type = first_number + times_sign + second_number + times_sign + third_number + equals_sign + first_number + times_sign + "(" + second_number + times_sign + blank + ")";
         result = third_number;
      break;
      case 4:
         horizontal_type = blank + times_sign + second_number + times_sign + third_number + equals_sign + first_number + times_sign + "(" + second_number + times_sign + third_number + ")";
         result = first_number;
      break;
      case 5:
         horizontal_type = first_number + times_sign + blank + times_sign + third_number + equals_sign + first_number + times_sign + "(" + second_number + times_sign + third_number + ")";
         result = second_number;
      break;
      case 6:
         horizontal_type = first_number + times_sign + second_number + times_sign + blank + equals_sign + first_number + times_sign + "(" + second_number + times_sign + third_number + ")";
         result = third_number;
      break;
      }
    }while(horizontal_type == pre_horizontal_type);
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  
  // 乘法分配律
  $("#btn_distributive_law_for_multiplication").click(function(){
   do{
   var blank_num = Math.floor(Math.random()*2)+1;
   if(blank_num == 1){      // 一般的，正向的
     first_number = (Math.floor(Math.random()*9)+1)*100;
     second_number = Math.floor(Math.random()*4)+1;
     third_number =  Math.floor(Math.random()*90)+10;
     var chooses=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
     var chooses_index = Math.floor(Math.random()*chooses.length);
     var choose = chooses[chooses_index];
     switch(choose)
     {
      case 1:
         horizontal_type = "(" + blank + plus_sign + second_number + ")" + times_sign + third_number + equals_sign + first_number + times_sign + third_number + plus_sign + second_number + times_sign + third_number;
         result = first_number;
      break;
      case 2:
         horizontal_type = "(" + first_number + plus_sign + blank + ")" + times_sign + third_number + equals_sign + first_number + times_sign + third_number + plus_sign + second_number + times_sign + third_number;
         result = second_number;
      break;
      case 3:
         horizontal_type = "(" + first_number + plus_sign + second_number + ")" + times_sign + blank + equals_sign + first_number + times_sign + third_number + plus_sign + second_number + times_sign + third_number;
         result = third_number;
      break;
      case 4:
         horizontal_type = "(" + first_number + plus_sign + second_number + ")" + times_sign + third_number + equals_sign + blank + times_sign + third_number + plus_sign + second_number + times_sign + third_number;
         result = first_number;
      break;
      case 5:
         horizontal_type = "(" + first_number + plus_sign + second_number + ")" + times_sign + third_number + equals_sign + first_number + times_sign + blank + plus_sign + second_number + times_sign + third_number;
         result = third_number;
      break;
      case 6:
         horizontal_type = "(" + first_number + plus_sign + second_number + ")" + times_sign + third_number + equals_sign + first_number + times_sign + third_number + plus_sign + blank + times_sign + third_number;
         result = second_number;
      break;
      case 7:
         horizontal_type = "(" + first_number + plus_sign + second_number + ")" + times_sign + third_number + equals_sign + first_number + times_sign + third_number + plus_sign + second_number + times_sign + blank;
         result = third_number;
      break;
      case 8:
         horizontal_type =  blank + times_sign + "(" + first_number + plus_sign + second_number + ")" + equals_sign + third_number + times_sign + first_number + plus_sign + third_number + times_sign + second_number;
         result = third_number;
      break;
      case 9:
         horizontal_type =  third_number + times_sign + "(" + blank + plus_sign + second_number + ")" + equals_sign + third_number + times_sign + first_number + plus_sign + third_number + times_sign + second_number;
         result = first_number;
      break;
      case 10:
         horizontal_type =  third_number + times_sign + "(" + first_number + plus_sign + blank + ")" + equals_sign + third_number + times_sign + first_number + plus_sign + third_number + times_sign + second_number;
         result = second_number;
      break;
      case 11:
         horizontal_type =  third_number + times_sign + "(" + first_number + plus_sign + second_number + ")" + equals_sign + blank + times_sign + first_number + plus_sign + third_number + times_sign + second_number;
         result = third_number;
      break;
      case 12:
         horizontal_type =  third_number + times_sign + "(" + first_number + plus_sign + second_number + ")" + equals_sign + third_number + times_sign + blank + plus_sign + third_number + times_sign + second_number;
         result = first_number;
      break;
      case 13:
         horizontal_type =  third_number + times_sign + "(" + first_number + plus_sign + second_number + ")" + equals_sign + third_number + times_sign + first_number + plus_sign + blank + times_sign + second_number;
         result = third_number;
      break;
      case 14:
         horizontal_type =  third_number + times_sign + "(" + first_number + plus_sign + second_number + ")" + equals_sign + third_number + times_sign + first_number + plus_sign + third_number + times_sign + blank;
         result = second_number;
      break;
     }
   }else{                // 逆向的分配
     var temp_result = (Math.floor(Math.random()*90)+10)*10;
     first_number = Math.floor(Math.random()*(temp_result-1))+1;
     second_number = temp_result - first_number;
     third_number =  Math.floor(Math.random()*90)+10;
     var chooses=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
     var chooses_index = Math.floor(Math.random()*chooses.length);
     var choose = chooses[chooses_index];
     switch(choose)
     {
      case 1:
         horizontal_type = first_number + times_sign + third_number + plus_sign + second_number + times_sign + third_number + equals_sign + "(" + blank + plus_sign + second_number + ")" + times_sign + third_number;
         result = first_number;
      break;
      case 2:
         horizontal_type = first_number + times_sign + third_number + plus_sign + second_number + times_sign + third_number + equals_sign + "(" + first_number + plus_sign + blank + ")" + times_sign + third_number;
         result = second_number;
      break;
      case 3:
         horizontal_type = first_number + times_sign + third_number + plus_sign + second_number + times_sign + third_number + equals_sign + "(" + first_number + plus_sign + second_number + ")" + times_sign + blank;
         result = third_number;
      break;
      case 4:
         horizontal_type = blank + times_sign + third_number + plus_sign + second_number + times_sign + third_number + equals_sign + "(" + first_number + plus_sign + second_number + ")" + times_sign + third_number;
         result = first_number;
      break;
      case 5:
         horizontal_type = first_number + times_sign + blank + plus_sign + second_number + times_sign + third_number + equals_sign + "(" + first_number + plus_sign + second_number + ")" + times_sign + third_number;
         result = third_number;
      break;
      case 6:
         horizontal_type = first_number + times_sign + third_number + plus_sign + blank + times_sign + third_number + equals_sign + "(" + first_number + plus_sign + second_number + ")" + times_sign + third_number;
         result = second_number;
      break;
      case 7:
         horizontal_type = first_number + times_sign + third_number + plus_sign + second_number + times_sign + blank + equals_sign + "(" + first_number + plus_sign + second_number + ")" + times_sign + third_number;
         result = third_number;
      break;
      case 8:
         horizontal_type = third_number + times_sign + first_number + plus_sign + third_number + times_sign + second_number + equals_sign +  blank + times_sign + "(" + first_number + plus_sign + second_number + ")";
         result = third_number;
      break;
      case 9:
         horizontal_type = third_number + times_sign + first_number + plus_sign + third_number + times_sign + second_number + equals_sign +  third_number + times_sign + "(" + blank + plus_sign + second_number + ")";
         result = first_number;
      break;
      case 10:
         horizontal_type = third_number + times_sign + first_number + plus_sign + third_number + times_sign + second_number  + equals_sign + third_number + times_sign + "(" + first_number + plus_sign + blank + ")";
         result = second_number;
      break;
      case 11:
         horizontal_type = blank + times_sign + first_number + plus_sign + third_number + times_sign + second_number + equals_sign +  third_number + times_sign + "(" + first_number + plus_sign + second_number + ")";
         result = third_number;
      break;
      case 12:
         horizontal_type = third_number + times_sign + blank + plus_sign + third_number + times_sign + second_number + equals_sign +  third_number + times_sign + "(" + first_number + plus_sign + second_number + ")";
         result = first_number;
      break;
      case 13:
         horizontal_type = third_number + times_sign + first_number + plus_sign + blank + times_sign + second_number + equals_sign + third_number + times_sign + "(" + first_number + plus_sign + second_number + ")";
         result = third_number;
      break;
      case 14:
         horizontal_type = third_number + times_sign + first_number + plus_sign + third_number + times_sign + blank + equals_sign +  third_number + times_sign + "(" + first_number + plus_sign + second_number + ")";
         result = second_number;
      break;
     }
   };
    }while(horizontal_type == pre_horizontal_type);
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 乘法运算定律的应用
  $("#btn_use_multiplication_laws").click(function(){
    do{
    var question_type = Math.floor(Math.random()*3);
    switch (question_type)
    {
    case 1:                    // 两数相乘的简便计算
      var temp_result_1 = (Math.floor(Math.random()*9)+1)*100;
      var temp_result_2 = Math.floor(Math.random()*4)+1;
      second_number = temp_result_1 + temp_result_2;
      first_number =  Math.floor(Math.random()*90)+10;
      result = first_number * second_number;
      var choose = Math.floor(Math.random()*2)+1;
      switch(choose)
      {
      case 1:
         horizontal_type =  first_number + times_sign + second_number + equals_sign;
      break;
      case 2:
         horizontal_type =  second_number + times_sign + first_number + equals_sign;
      break;
      };
    break;
    case 2:                // 三个数相乘的简便计算
      var temp_result = (Math.floor(Math.random()*8)+2)*100;
      do{
        first_number = Math.floor(Math.random()*90)+10;
        var fail_flag = false;
	if(first_number%10 == 0){fail_flag = true;};
        if(first_number%5 == 0){fail_flag = true;};
      }while(fail_flag == true);
      do{
        second_number = Math.floor(Math.random()*8)+2;
        third_number = temp_result / second_number;
        var fail_flag = false;
	if(third_number%100 == 0){fail_flag = true;};
        if(Math.floor(third_number) != third_number){fail_flag = true;};
      }while( fail_flag == true);
      result = first_number * second_number * third_number;
      var choose = Math.floor(Math.random()*2)+1;
      switch(choose)
      {
      case 1:
         horizontal_type = first_number + times_sign + second_number + times_sign + third_number + equals_sign;
      break;
      case 2:
         horizontal_type = second_number + times_sign + first_number + times_sign + third_number + equals_sign;
      break;
      }
    break;
    case 0:               // 四个数相乘的简便计算
      var temp_result = (Math.floor(Math.random()*90)+10)*10;
      first_number = Math.floor(Math.random()*(temp_result-1))+1;
      second_number = temp_result - first_number;
      third_number =  Math.floor(Math.random()*90)+10;
      result = temp_result * third_number;
      var choose = Math.floor(Math.random()*3)+1;
      switch(choose)
      {
      case 1:
         horizontal_type = first_number + times_sign + third_number + plus_sign + second_number + times_sign + third_number + equals_sign;
      break;
      case 2:
         horizontal_type = first_number + times_sign + third_number + plus_sign + third_number + times_sign + second_number + equals_sign;
      break;
      case 3:
         horizontal_type = third_number + times_sign + first_number + plus_sign + third_number + times_sign + second_number + equals_sign;
      break;
      case 4:
         horizontal_type = third_number + times_sign + first_number + plus_sign + second_number + times_sign + third_number + equals_sign;
      break;
     }
     break;
    };
    }while(horizontal_type == pre_horizontal_type);
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 简便计算
  // 连减
  $("#btn_shortcut_serial_subtractions").click(function(){
    do{
    var question_type = Math.floor(Math.random()*2)+1;
    switch (question_type)
    {
    case 1:                    // 后两个减数交换，如137-25-37
      var temp_result_1 = (Math.floor(Math.random()*9)+1)*100;
      do{
        first_number = Math.floor(Math.random()*999)+1;
        var fail_flag = false;
	if(first_number%10 == 0){fail_flag = true;};
	if(first_number <= temp_result_1){fail_flag = true;};
      }while(fail_flag == true);
      second_number = Math.floor(Math.random()*(temp_result_1-11))+11;
      third_number =  temp_result_1 - second_number;
      result = first_number - temp_result_1;
      horizontal_type =  first_number + minus_sign + second_number + minus_sign + third_number + equals_sign;
    break;
    case 2:                // 后两个减数结合
      var temp_result_1 = (Math.floor(Math.random()*9)+1)*100;
      do{
        var temp_result_2 = Math.floor(Math.random()*9)*100;
      }while(temp_result_2 >= temp_result_1);
      temp_result_3 = Math.floor(Math.random()*99)+1;
      first_number = temp_result_1 + temp_result_3;
      third_number = temp_result_2 + temp_result_3;
      do{
        var second_number = Math.floor(Math.random()*999);
      }while(second_number > first_number - third_number);
      result = first_number - second_number - third_number;
      var choose = Math.floor(Math.random()*3)+1;
      switch(choose)
      {
      case 1:                 // 后两数相减
         horizontal_type = first_number + minus_sign + second_number + minus_sign + third_number + equals_sign;
      break;
      case 2:                 // 后两数相加（一）
         horizontal_type = first_number + minus_sign + "(" + second_number + plus_sign + third_number + ")" + equals_sign;
      break;
      case 3:                 // 后两数相加（一）
         horizontal_type = first_number + minus_sign + "(" + third_number + plus_sign + second_number + ")" + equals_sign;
      break;
      }
    break;
    };
    }while(horizontal_type == pre_horizontal_type);
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 加减
  $("#btn_shortcut_addition_subtractions").click(function(){
    do{
    var operators_num = Math.floor(Math.random()*2)+2;
    switch (operators_num)
    {
    case 2:                    // 三个数的加减简便运算
      var question_type = Math.floor(Math.random()*3)+1;
      switch (question_type)
      {
      case 1:                    // a-b+c=a+c-b;  还想做一个a-b+c=a-(b-c)，就是不知道加括号会不会超出范围。
        var temp_result_1 = (Math.floor(Math.random()*9)+1)*100;
        first_number = Math.floor(Math.random()*temp_result_1);
        second_number = Math.floor(Math.random()*temp_result_1);
	third_number = temp_result_1 - first_number;
        result = temp_result_1 - second_number;
        horizontal_type =  first_number + minus_sign + second_number + plus_sign + third_number + equals_sign;
      break;
      case 2:                   // a+b-c=a-c+b
        var temp_result_1 = (Math.floor(Math.random()*9)+1)*100;
        third_number = Math.floor(Math.random()*99)+1;
        first_number = temp_result_1 + third_number;
        second_number = (Math.floor(Math.random()*9)+1)*100;
        result = temp_result_1 + second_number;
        horizontal_type =  first_number + plus_sign + second_number + minus_sign + third_number + equals_sign;
      break;
      case 3:                  // a+b-c=a+(b-c);
        var temp_result_1 = (Math.floor(Math.random()*9)+1)*100;
        third_number = Math.floor(Math.random()*99)+1;
        first_number = temp_result_1 + third_number;
        second_number = (Math.floor(Math.random()*9)+1)*100;
        result = second_number + temp_result_1;
        horizontal_type =  second_number + plus_sign + first_number + minus_sign + third_number + equals_sign;
      break;
      }
    break;
    case 3:            // 三个操作符四个数的加减简便运算
      var question_type = Math.floor(Math.random()*3)+1;
      switch (question_type)
      {
      case 1:                    // 一个减号，两个加号
        var temp_result_1 = (Math.floor(Math.random()*9)+1)*100;
        second_number = Math.floor(Math.random()*99)+1;
        first_number = temp_result_1 + second_number;
        var temp_result_2 = (Math.floor(Math.random()*9)+1)*100;
        third_number = Math.floor(Math.random()*temp_result_2)+1;
        fourth_number = temp_result_2 - third_number;
        result = first_number - second_number + third_number + fourth_number;
        var question_type_1 = Math.floor(Math.random()*3)+1;
        switch (question_type_1)
        {
        case 1:                    // a+c+d-b=(a-b)+(c+d)
        horizontal_type = first_number + plus_sign + third_number + plus_sign + fourth_number + minus_sign + second_number + equals_sign;
        break;
        case 2:                    // c+a+d-b=(a-b)+(c+d)
        horizontal_type = third_number + plus_sign + first_number + plus_sign + fourth_number + minus_sign + second_number + equals_sign;
        break;
        case 3:                    // c+d+a-b=(a-b)+(c+d)
        horizontal_type = third_number + plus_sign + fourth_number + plus_sign + first_number + minus_sign + second_number + equals_sign;
        break;
        };
      break;
      case 2:           // 两个减号，一个加号： (a-b)+(c-d)
        var temp_result_1 = (Math.floor(Math.random()*9)+1)*100;
        second_number = Math.floor(Math.random()*99)+1;
        first_number = temp_result_1 + second_number;
        var temp_result_2 = Math.floor(Math.random()*10);
        var temp_result_3 = Math.floor(Math.random()*99)+1;
        third_number = temp_result_2*100+temp_result_3;
        var temp_result_4 = Math.floor(Math.random()*temp_result_2)*100;
        fourth_number = temp_result_3 + temp_result_4;
        result = first_number - second_number + third_number - fourth_number;
        var question_type_2 = Math.floor(Math.random()*3)+1;
        switch (question_type_2)
        {
        case 1:                    // a+c-d-b
          horizontal_type = first_number + plus_sign + third_number + minus_sign + fourth_number + minus_sign + second_number + equals_sign;
        break;
	case 2:                    // a-d-b+c
          horizontal_type = first_number + minus_sign + fourth_number + minus_sign + second_number + plus_sign + third_number + equals_sign;
        break;
	case 3:                    // a-d+c-b
          horizontal_type = first_number + minus_sign + fourth_number + plus_sign + third_number + minus_sign + second_number + equals_sign;
        break;
	}
      break;
      case 3:            // 两个减号，一个加号：a-b-c+d=a-(b+c)+d
        var temp_result_1 = (Math.floor(Math.random()*8)+2)*100;
        first_number = Math.floor(Math.random()*(temp_result_1-10))+10;
        second_number = temp_result_1 - first_number;
	do{
          var temp_result_2 = (Math.floor(Math.random()*9)+1)*100;
	}while(temp_result_2 > temp_result_1);
        third_number = Math.floor(Math.random()*(temp_result_2-10)) + 10;
        fourth_number = temp_result_2 - third_number;
        var question_type_1 = Math.floor(Math.random()*3)+1;
        result = first_number + second_number - third_number - fourth_number;
        switch (question_type_1)
        {
	case 1:
          horizontal_type = first_number + minus_sign + third_number + plus_sign + second_number + minus_sign + fourth_number + equals_sign;
        break;
        case 2:
          horizontal_type = first_number + minus_sign + third_number+ minus_sign + fourth_number + plus_sign + second_number  + equals_sign;
        break;
        case 3:
          horizontal_type = first_number + plus_sign + second_number + minus_sign + third_number+ minus_sign + fourth_number  + equals_sign;
        break;
        };
      break;
      };
    break;
    };
    }while(horizontal_type == pre_horizontal_type);
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 连除
  $("#btn_shortcut_serial_division").click(function(){
    do{
    var question_type = Math.floor(Math.random()*3)+1;
    switch (question_type)
    {
    case 1:                    // 后两个除数交换，如126/21/3=2
      var choose = Math.floor(Math.random()*3)+1;
      switch(choose)
      {
      case 1:                 // 计算时除以两位数
        third_number =  Math.floor(Math.random()*89)+11;   //第三个数：11-99
        var temp_factories = [2, 5, 10, 20, 100];
        var temp_factories_index = Math.floor(Math.random()*temp_factories.length);
        var temp_factory = temp_factories[temp_factories_index];
        first_number = third_number * temp_factory;        // 第一个数：第三个数的倍数
        do{
          second_number =  Math.floor(Math.random()*98)+2;  // 第二个数： 2-99
	  var fail_flag = false;
	  if(temp_factory%second_number != 0){fail_flag = true};
	  if(second_number == third_number){fail_flag = true};
        }while(fail_flag == true);
        result = temp_factory/second_number;
      break;
      case 2:                 // 计算时除以一位数
        third_number =  Math.floor(Math.random()*7)+3;   // 第三个数： 3-9
        var temp_factories_1 = [10, 100];
        var temp_factories_index_1 = Math.floor(Math.random()*temp_factories_1.length);
        var temp_factory_1 = temp_factories_1[temp_factories_index_1];
        var temp_factory_2 = Math.floor(Math.random()*8)+2;
        do{
          first_number = third_number * temp_factory_1 * temp_factory_2;     // 第一个数：第三个数的20-900倍
	  if(Math.floor(third_number*temp_factory_2/10) >= third_number){fail_flag = true};
        }while(fail_flag == true);
        var temp_factory = first_number / third_number;
        do{
          second_number =  Math.floor(Math.random()*8)+2;          // 第二个数： 2-9
	  var fail_flag = false;
	  if(temp_factory%second_number != 0){fail_flag = true};
	  if(second_number >= third_number){fail_flag = true};
        }while(fail_flag == true);
        result = temp_factory/second_number;
      break;
      }
      horizontal_type = first_number + division_sign + second_number + division_sign + third_number + equals_sign;
    break;
    case 2:                // 两个除数变乘数来结合（数字应该可以更大些，哈哈，怕大脑罢工）
      var temp_factories = [2, 10];
      var temp_factories_index = Math.floor(Math.random()*temp_factories.length);
      result = temp_factories[temp_factories_index];
      third_number =  Math.floor(Math.random()*8)+2;
      second_number =  Math.floor(Math.random()*998)+2;
      first_number = result * second_number * third_number;
      horizontal_type = first_number + division_sign + second_number + division_sign + third_number + equals_sign;
    break;
    case 3:                // 后两乘数拆分为连除
      result = Math.floor(Math.random()*9)+1;
      second_number =  Math.floor(Math.random()*89)+11;
      third_number =  Math.floor(Math.random()*8)+2;
      temp_result_1 = second_number * third_number;
      first_number = result * second_number * third_number;
      horizontal_type = first_number + division_sign + "(" + second_number + times_sign + third_number + ")" + equals_sign;
    break;
    case 4:                 // 两数相除，除数可分解
      result = Math.floor(Math.random()*9)+1;
      second_number =  Math.floor(Math.random()*8)+2;
      third_number =  Math.floor(Math.random()*8)+2;
      temp_result_1 = second_number * third_number;
      first_number = result * second_number * third_number;
      horizontal_type = first_number + division_sign + temp_result_1 + equals_sign;
    break;
    };
    }while(horizontal_type == pre_horizontal_type);
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 乘除
  $("#btn_shortcut_multiplication_division").click(function(){
    do{
    var operators_num = Math.floor(Math.random()*3)+1;
    switch (operators_num)
    {
    case 1:                    // 两个数相乘
      var first_number_ready = [25, 125];
      var first_number_ready_index = Math.floor(Math.random()*2);
      first_number = first_number_ready[first_number_ready_index];
      var temp_factory_1 = 4;
      var temp_factory_2_all = [3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19];
      var temp_factory_2_all_index = Math.floor(Math.random()*temp_factory_2_all.length);
      var temp_factory_2 = temp_factory_2_all[temp_factory_2_all_index];
      second_number = temp_factory_1 * temp_factory_2;
      result = first_number * second_number;
      var question_type = Math.floor(Math.random()*2)+1;
      switch (question_type)
      {
      case 1:
        horizontal_type = first_number + times_sign + second_number + equals_sign;
      break;
      case 2:
        horizontal_type = second_number + times_sign + first_number + equals_sign;
      break;
      }
    break;
    case 2:                    // 三个数的乘除
      var question_type = Math.floor(Math.random()*3)+1;
      switch (question_type)
      {
      case 1:                    // 除法优先
        var temp_result_1 = Math.floor(Math.random()*8)+2;
        third_number = Math.floor(Math.random()*8)+2;
        first_number = third_number * temp_result_1;
        second_number = Math.floor(Math.random()*88)+11;
        result = first_number * second_number / third_number;
        var question_type_1 = Math.floor(Math.random()*3)+1;
        switch (question_type_1)
        {
        case 1:
          horizontal_type =  first_number + times_sign + second_number + division_sign + third_number + equals_sign;
        break;
        case 2:
          horizontal_type =  second_number + times_sign + first_number + division_sign + third_number + equals_sign;
        break;
        case 3:
          horizontal_type =  second_number + division_sign + third_number + times_sign + first_number + equals_sign;
        break;
	}
      break;
      case 2:                   // 乘法优先
        first_number =  Math.floor(Math.random()*8)+2;
        third_number = Math.floor(Math.random()*8)+2;
        do{
          second_number = Math.floor(Math.random()*98)+2;
	}while(first_number*third_number%second_number != 0);
        result = first_number * third_number / second_number;
        horizontal_type =  first_number + division_sign + second_number + times_sign + third_number + equals_sign;
      break;
      }
    break;
    case 3:            // 三个操作符四个数的乘除简便运算
      var question_type = Math.floor(Math.random()*3)+1;
      switch (question_type)
      {
      case 1:                    // 一个除号，两个乘号
        var temp_result_1 = Math.floor(Math.random()*8)+2;
        second_number = Math.floor(Math.random()*98)+2;
        first_number = temp_result_1 * second_number;
        var third_number_ready = [25, 125];
        var third_number_ready_index = Math.floor(Math.random()*2);
        third_number = third_number_ready[third_number_ready_index];
        var temp_factory_1 = 4;
        var temp_factory_2_all = [3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19];
        var temp_factory_2_all_index = Math.floor(Math.random()*temp_factory_2_all.length);
        var temp_factory_2 = temp_factory_2_all[temp_factory_2_all_index];
        fourth_number = temp_factory_1 * temp_factory_2;
        result = first_number / second_number * third_number * fourth_number;
        var question_type_1 = Math.floor(Math.random()*3)+1;
        switch (question_type_1)
        {
        case 1:                    // a*c*d/b=(a/b)*(c*d)
        horizontal_type = first_number + times_sign + third_number + times_sign + fourth_number + division_sign + second_number + equals_sign;
        break;
        case 2:                    // c*a*d/b=(a/b)*(c*d)
        horizontal_type = third_number + times_sign + first_number + times_sign + fourth_number + division_sign+ second_number + equals_sign;
        break;
        case 3:                    // c*d*a/b=(a/b)*(c*d)
        horizontal_type = third_number + times_sign + fourth_number + times_sign + first_number + division_sign+ second_number + equals_sign;
        break;
        };
      break;
      case 2:           // 两个除号，一个乘号： (a/b)*(c/d)
        var temp_result_1 = Math.floor(Math.random()*8)+2;
        second_number = Math.floor(Math.random()*98)+2;
        first_number = temp_result_1 * second_number;
        var temp_result_2 = Math.floor(Math.random()*8)+2;
        fourth_number = Math.floor(Math.random()*98)+2;
        third_number = temp_result_2 * fourth_number;
        result = first_number / second_number * third_number / fourth_number;
        var question_type_2 = Math.floor(Math.random()*3)+1;
        switch (question_type_2)
        {
        case 1:                    // a*c/d/b
          horizontal_type = first_number + times_sign + third_number + division_sign + fourth_number + division_sign + second_number + equals_sign;
        break;
	case 2:                    // a/d/b*c
          horizontal_type = first_number + division_sign + fourth_number + division_sign + second_number + times_sign + third_number + equals_sign;
        break;
	case 3:                    // a/d*c/b
          horizontal_type = first_number + division_sign + fourth_number + times_sign + third_number + division_sign + second_number + equals_sign;
        break;
	}
      break;
      case 3:            // 两个除号，一个乘号：a/b/c*d=a/(b*c)*d
        var second_number_ready = [25, 125];
        var second_number_ready_index = Math.floor(Math.random()*2);
        second_number = second_number_ready[second_number_ready_index];
        var temp_factory_1 = 4;
        var temp_factory_2_all = [3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19];
        var temp_factory_2_all_index = Math.floor(Math.random()*temp_factory_2_all.length);
        var temp_factory_2 = temp_factory_2_all[temp_factory_2_all_index];
        third_number = temp_factory_1 * temp_factory_2;
        var temp_result_3 = Math.floor(Math.random()*9)+1;
        first_number = second_number * third_number * temp_result_3;
	fourth_number = Math.floor(Math.random()*98)+2;
        result = first_number / second_number / third_number * fourth_number;
        switch (question_type_1)
        {
	case 1:
          horizontal_type = first_number + division_sign + third_number + times_sign + second_number + division_sign + fourth_number + equals_sign;
        break;
        case 2:
          horizontal_type = first_number + division_sign + third_number+ division_sign + fourth_number + times_sign + second_number  + equals_sign;
        break;
        case 3:
          horizontal_type = first_number + times_sign + second_number + division_sign + third_number+ division_sign + fourth_number  + equals_sign;
        break;
        };
      break;
      };
    break;
    };
    }while(horizontal_type == pre_horizontal_type);
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 乘加
  $("#btn_shortcut_multiplication_addition").click(function(){
    do{
      var add_or_subtract = Math.floor(Math.random()*4)+1;
      switch (add_or_subtract)
      {
      case 1:                  // 乘法和加法
        first_number = Math.floor(Math.random()*89)+11;
	var temp_result_1 = (Math.floor(Math.random()*9)+1)*100;
        second_number = Math.floor(Math.random()*(temp_result_1-1))+1;
        third_number = temp_result_1 - second_number;
	result = first_number * temp_result_1;
        if(third_number == 1){
	  var question_type_1 = Math.floor(Math.random()*2)+1;
          if(question_type_1 == 1){
            horizontal_type = first_number + times_sign + second_number + plus_sign + first_number + equals_sign;
	  }else{
            horizontal_type = first_number + plus_sign + first_number + times_sign + second_number + equals_sign;
	  };
        }else{
	var question_type_1 = Math.floor(Math.random()*2)+1;
        switch (question_type_1)
        {
        case 1:
          horizontal_type = first_number + times_sign + second_number + plus_sign + first_number +times_sign + third_number + equals_sign;
        break;
	case 2:
          horizontal_type = second_number + times_sign + first_number + plus_sign + first_number +times_sign + third_number + equals_sign;
	break;
	case 3:
          horizontal_type = first_number + times_sign + second_number + plus_sign + third_number +times_sign + first_number + equals_sign;
	break;
	case 4:
          horizontal_type = second_number + times_sign + first_number + plus_sign + third_number +times_sign + first_number + equals_sign;
	break;
	}
	}
      break;
      case 2:                     // 乘法和减法
        first_number = Math.floor(Math.random()*89)+11;
	var temp_result_1 = (Math.floor(Math.random()*9)+1)*100;
        third_number = Math.floor(Math.random()*(99-1))+1;
        second_number = temp_result_1 + third_number;
	result = first_number * temp_result_1;
        if(third_number == 1){
          horizontal_type = first_number + times_sign + second_number + minus_sign + first_number + equals_sign;
        }else{
	var question_type_1 = Math.floor(Math.random()*2)+1;
        switch (question_type_1)
        {
        case 1:              // a*b-a*c
          horizontal_type = first_number + times_sign + second_number + minus_sign + first_number +times_sign + third_number + equals_sign;
        break;
	case 2:             // b*a-a*c
          horizontal_type = second_number + times_sign + first_number + minus_sign + first_number +times_sign + third_number + equals_sign;
	break;
	case 3:             // a*b-c*a
          horizontal_type = first_number + times_sign + second_number + minus_sign + third_number +times_sign + first_number + equals_sign;
	break;
	case 4:            // b*a-c*a
          horizontal_type = second_number + times_sign + first_number + minus_sign + third_number +times_sign + first_number + equals_sign;
	break;
	};
	};
      break;
      case 3:               // 除法和加法
        first_number = Math.floor(Math.random()*8)+2;
        do{
	  var temp_result_1 = (Math.floor(Math.random()*9)+1)*100;
	}while(temp_result_1%first_number != 0);
        second_number = Math.floor(Math.random()*(temp_result_1-1))+1;
        third_number = temp_result_1 - second_number;
	result = temp_result_1/first_number;
        if(third_number == 1){
          horizontal_type = second_number + division_sign + first_number + plus_sign + first_number + equals_sign;
	}else{
          horizontal_type = second_number + division_sign + first_number + plus_sign + third_number +division_sign + first_number + equals_sign;
	};
      break;
      case 4:               // 除法和减法
        first_number = Math.floor(Math.random()*8)+2;
        do{
	  var temp_result_1 = (Math.floor(Math.random()*9)+1)*100;
	}while(temp_result_1%first_number != 0);
        third_number = Math.floor(Math.random()*(99-1))+1;
        second_number = temp_result_1 + third_number;
	result = temp_result_1/first_number;
        if(third_number == 1){
          horizontal_type = second_number + division_sign + first_number + minus_sign + first_number + equals_sign;
	}else{
        horizontal_type = second_number + division_sign + first_number + minus_sign + third_number +division_sign + first_number + equals_sign;
	};
      break;
      }
    }while(horizontal_type == pre_horizontal_type);
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 二十一单元： 小数的加法和减法
  // 基本
    $("#btn_decimal_add_or_subtract").click(function(){
      do{
      var add_or_subtract = Math.floor(Math.random()*2)+1;
      switch(add_or_subtract)
      {
      case 1:
        first_number = (Math.floor(Math.random()*999)+1)/100;
        second_number = (Math.floor(Math.random()*999)+1)/100;
        result = first_number + second_number;
	horizontal_type = first_number + plus_sign + second_number + equals_sign;
      break;
      case 2:
        first_number_ready = (Math.floor(Math.random()*999)+1);
        first_number = first_number_ready / 100;
        do{
          second_number_ready = Math.floor(Math.random()*999)+1;
          second_number = second_number_ready/100;
	}while(first_number <= second_number);
        result = (first_number_ready - second_number_ready)/100;
	horizontal_type = first_number + minus_sign + second_number + equals_sign;
      break;
      }
    }while(horizontal_type == pre_horizontal_type);
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
    });

  // 混合
  $("#btn_decimal_mixed_operation").click(function(){
    var set_top_number = 10000;
    var set_number = set_top_number + 1;
    var temp_result =0;
    var operators=[" + ", " - "];
    var operator_index = Math.floor(Math.random()*operators.length);
    var first_operator = operators[operator_index];
    operators.splice(operator_index, 1);
    do{
    if (first_operator == " + "){
      do{
        first_number = Math.floor(Math.random()*set_number);
        second_number = Math.floor(Math.random()*set_number);
        var temp_result = first_number + second_number;
      }while(temp_result>set_top_number);
      first_number = first_number / 100;
      second_number = second_number / 100;
      third_number = Math.floor(Math.random()*temp_result)/100;
      var result_ready = temp_result - third_number;
      result = result_ready - third_number;
    }else{
      do{
        first_number = Math.floor(Math.random()*set_number);
        second_number = Math.floor(Math.random()*set_number);
        var temp_result = first_number - second_number;
      }while(temp_result<0);
      first_number = first_number / 100;
      second_number = second_number / 100;
      do{
      third_number = Math.floor(Math.random()*(set_number-temp_result));
      result = temp_result + third_number;
      }while(result > set_top_number);
      third_number = third_number / 100;
      result = result / 100;
    };
    horizontal_type = first_number + first_operator + second_number + operators + third_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + first_operator + second_number + operators + third_number + " = " + result; //测试运算结果。
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 简便
  $("#btn_decimal_add_and_subtract_shortcut").click(function(){
    do{
      var shortcut_type = Math.floor(Math.random()*5);
      switch (shortcut_type)
      {
      case 0: //加法运算定律的应用（三个加数）
      var temp_result_1 = (Math.floor(Math.random()*9)+1)*100;
      var temp_result_2 = Math.floor(Math.random()*999)+1;
      first_number = Math.floor(Math.random()*temp_result_1-1)+1;
      second_number = temp_result_1 - first_number;
      result = temp_result_1 + temp_result_2;

      first_number = first_number / 100;
      second_number = second_number / 100;
      temp_result_2 = temp_result_2 / 100;
      result = result / 100;

      var shuffle_num=[temp_result_2, first_number, second_number];
      for(var j, x, i = shuffle_num.length;
        i; 
	j = parseInt(Math.random() * i), 
	x = shuffle_num[--i], 
	shuffle_num[i] = shuffle_num[j], 
	shuffle_num[j] = x);
      horizontal_type = shuffle_num[0] + plus_sign + shuffle_num[1] + plus_sign + shuffle_num[2] + equals_sign;
      break;
      case 1: //加法运算定律的应用（四个加数）
      var temp_result_1 = (Math.floor(Math.random()*9)+1)*100;
      var temp_result_2 = (Math.floor(Math.random()*9)+1)*100;
      first_number = Math.floor(Math.random()*temp_result_1-1)+1;
      second_number = temp_result_1 - first_number;
      third_number = Math.floor(Math.random()*temp_result_2-1)+1;
      fourth_number = temp_result_2 - third_number;
      result = temp_result_1 + temp_result_2;

      first_number = first_number / 100;
      second_number = second_number / 100;
      third_number = third_number / 100;
      fourth_number = fourth_number /100;
      result = result / 100;

      var shuffle_num=[first_number, second_number, third_number, fourth_number];
      for(var j, x, i = shuffle_num.length;
        i; 
	j = parseInt(Math.random() * i), 
	x = shuffle_num[--i], 
	shuffle_num[i] = shuffle_num[j], 
	shuffle_num[j] = x);
      horizontal_type = shuffle_num[0] + plus_sign + shuffle_num[1] + plus_sign + shuffle_num[2] + plus_sign + shuffle_num[3] + equals_sign;
      break;
    case 2: // 连减
    var question_type = Math.floor(Math.random()*2)+1;
    switch (question_type)
    {
    case 1:                    // 后两个减数结合
      var temp_result_1 = (Math.floor(Math.random()*9)+1)*100;
      do{
        first_number = Math.floor(Math.random()*999)+1;
        var fail_flag = false;
	if(first_number%10 == 0){fail_flag = true;};
	if(first_number <= temp_result_1){fail_flag = true;};
      }while(fail_flag == true);
      second_number = Math.floor(Math.random()*(temp_result_1-11))+11;
      third_number =  temp_result_1 - second_number;
      result = first_number - temp_result_1;

      first_number = first_number / 100;
      second_number = second_number / 100;
      third_number = third_number / 100;
      result = result / 100;

      horizontal_type =  first_number + minus_sign + second_number + minus_sign + third_number + equals_sign;
    break;
    case 2:                // 后两个减数交换，如137-25-37
      var temp_result_1 = (Math.floor(Math.random()*9)+1)*100;
      do{
        var temp_result_2 = Math.floor(Math.random()*9)*100;
      }while(temp_result_2 >= temp_result_1);
      temp_result_3 = Math.floor(Math.random()*99)+1;
      first_number = temp_result_1 + temp_result_3;
      third_number = temp_result_2 + temp_result_3;
      do{
        var second_number = Math.floor(Math.random()*999);
      }while(second_number > first_number - third_number);
      result = first_number - second_number - third_number;

      first_number = first_number / 100;
      second_number = second_number / 100;
      third_number = third_number / 100;
      result = result / 100;

      var choose = Math.floor(Math.random()*3)+1;
      switch(choose)
      {
      case 1:                 // 后两数相减
         horizontal_type = first_number + minus_sign + second_number + minus_sign + third_number + equals_sign;
      break;
      case 2:                 // 后两数相加（一）
         horizontal_type = first_number + minus_sign + "(" + second_number + plus_sign + third_number + ")" + equals_sign;
      break;
      case 3:                 // 后两数相加（一）
         horizontal_type = first_number + minus_sign + "(" + third_number + plus_sign + second_number + ")" + equals_sign;
      break;
      }
    break;
    };
    break;
    case 3: // 加减
    var operators_num = Math.floor(Math.random()*2)+2;
    switch (operators_num)
    {
    case 2:                    // 三个数的加减简便运算
      var question_type = Math.floor(Math.random()*3)+1;
      switch (question_type)
      {
      case 1:                    // a-b+c=a+c-b;  还想做一个a-b+c=a-(b-c)，就是不知道加括号会不会超出范围。
        var temp_result_1 = (Math.floor(Math.random()*9)+1)*100;
        first_number = Math.floor(Math.random()*temp_result_1);
        second_number = Math.floor(Math.random()*temp_result_1);
	third_number = temp_result_1 - first_number;
        result = temp_result_1 - second_number;

      first_number = first_number / 100;
      second_number = second_number / 100;
      third_number = third_number / 100;
      result = result / 100;

        horizontal_type =  first_number + minus_sign + second_number + plus_sign + third_number + equals_sign;
      break;
      case 2:                   // a+b-c=a-c+b
        var temp_result_1 = (Math.floor(Math.random()*9)+1)*100;
        third_number = Math.floor(Math.random()*99)+1;
        first_number = temp_result_1 + third_number;
        second_number = (Math.floor(Math.random()*9)+1)*100;
        result = temp_result_1 + second_number;

      first_number = first_number / 100;
      second_number = second_number / 100;
      third_number = third_number / 100;
      result = result / 100;

        horizontal_type =  first_number + plus_sign + second_number + minus_sign + third_number + equals_sign;
      break;
      case 3:                  // a+b-c=a+(b-c);
        var temp_result_1 = (Math.floor(Math.random()*9)+1)*100;
        third_number = Math.floor(Math.random()*99)+1;
        first_number = temp_result_1 + third_number;
        second_number = (Math.floor(Math.random()*9)+1)*100;
        result = second_number + temp_result_1;

      first_number = first_number / 100;
      second_number = second_number / 100;
      third_number = third_number / 100;
      result = result / 100;

        horizontal_type =  second_number + plus_sign + first_number + minus_sign + third_number + equals_sign;
      break;
      }
    break;
    case 3:            // 三个操作符四个数的加减简便运算
      var question_type = Math.floor(Math.random()*3)+1;
      switch (question_type)
      {
      case 1:                    // 一个减号，两个加号
        var temp_result_1 = (Math.floor(Math.random()*9)+1)*100;
        second_number = Math.floor(Math.random()*99)+1;
        first_number = temp_result_1 + second_number;
        var temp_result_2 = (Math.floor(Math.random()*9)+1)*100;
        third_number = Math.floor(Math.random()*temp_result_2)+1;
        fourth_number = temp_result_2 - third_number;
        result = first_number - second_number + third_number + fourth_number;

      first_number = first_number / 100;
      second_number = second_number / 100;
      third_number = third_number / 100;
      fourth_number = fourth_number / 100;
      result = result / 100;

        var question_type_1 = Math.floor(Math.random()*3)+1;
        switch (question_type_1)
        {
        case 1:                    // a+c+d-b=(a-b)+(c+d)
        horizontal_type = first_number + plus_sign + third_number + plus_sign + fourth_number + minus_sign + second_number + equals_sign;
        break;
        case 2:                    // c+a+d-b=(a-b)+(c+d)
        horizontal_type = third_number + plus_sign + first_number + plus_sign + fourth_number + minus_sign + second_number + equals_sign;
        break;
        case 3:                    // c+d+a-b=(a-b)+(c+d)
        horizontal_type = third_number + plus_sign + fourth_number + plus_sign + first_number + minus_sign + second_number + equals_sign;
        break;
        };
      break;
      case 2:           // 两个减号，一个加号： (a-b)+(c-d)
        var temp_result_1 = (Math.floor(Math.random()*9)+1)*100;
        second_number = Math.floor(Math.random()*99)+1;
        first_number = temp_result_1 + second_number;
        var temp_result_2 = Math.floor(Math.random()*10);
        var temp_result_3 = Math.floor(Math.random()*99)+1;
        third_number = temp_result_2*100+temp_result_3;
        var temp_result_4 = Math.floor(Math.random()*temp_result_2)*100;
        fourth_number = temp_result_3 + temp_result_4;
        result = first_number - second_number + third_number - fourth_number;

      first_number = first_number / 100;
      second_number = second_number / 100;
      third_number = third_number / 100;
      fourth_number = fourth_number / 100;
      result = result / 100;

        var question_type_2 = Math.floor(Math.random()*3)+1;
        switch (question_type_2)
        {
        case 1:                    // a+c-d-b
          horizontal_type = first_number + plus_sign + third_number + minus_sign + fourth_number + minus_sign + second_number + equals_sign;
        break;
	case 2:                    // a-d-b+c
          horizontal_type = first_number + minus_sign + fourth_number + minus_sign + second_number + plus_sign + third_number + equals_sign;
        break;
	case 3:                    // a-d+c-b
          horizontal_type = first_number + minus_sign + fourth_number + plus_sign + third_number + minus_sign + second_number + equals_sign;
        break;
	}
      break;
      case 3:            // 两个减号，一个加号：a-b-c+d=a-(b+c)+d
        var temp_result_1 = (Math.floor(Math.random()*8)+2)*100;
        first_number = Math.floor(Math.random()*(temp_result_1-10))+10;
        second_number = temp_result_1 - first_number;
	do{
          var temp_result_2 = (Math.floor(Math.random()*9)+1)*100;
	}while(temp_result_2 > temp_result_1);
        third_number = Math.floor(Math.random()*(temp_result_2-10)) + 10;
        fourth_number = temp_result_2 - third_number;
        var question_type_1 = Math.floor(Math.random()*3)+1;
        result = first_number + second_number - third_number - fourth_number;

      first_number = first_number / 100;
      second_number = second_number / 100;
      third_number = third_number / 100;
      fourth_number = fourth_number / 100;
      result = result / 100;

        switch (question_type_1)
        {
	case 1:
          horizontal_type = first_number + minus_sign + third_number + plus_sign + second_number + minus_sign + fourth_number + equals_sign;
        break;
        case 2:
          horizontal_type = first_number + minus_sign + third_number+ minus_sign + fourth_number + plus_sign + second_number  + equals_sign;
        break;
        case 3:
          horizontal_type = first_number + plus_sign + second_number + minus_sign + third_number+ minus_sign + fourth_number  + equals_sign;
        break;
        };
      break;
      };
    break;
    };
    break;
    };
    }while(horizontal_type == pre_horizontal_type);
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 二十二单元：小数乘法
  // 乘整十百千
  $("#btn_decimal_multiple_round_integer").click(function(){
    do{ 
      var multiple_times = [10, 100, 1000];
      var multiple_times_index_1 = Math.floor(Math.random()*multiple_times.length);
      var multiple_time_1 = multiple_times[multiple_times_index_1];
      do{
        var multiple_times_index_2 = Math.floor(Math.random()*multiple_times.length);
      }while(multiple_times_index_1 == multiple_times_index_2);
      var multiple_time_2 = multiple_times[multiple_times_index_2];
      first_number_ready = Math.floor(Math.random()*999)+1;
      first_number = first_number_ready/multiple_time_1;
      second_number = multiple_time_2;
      result = first_number_ready * second_number/multiple_time_1;
      horizontal_type = first_number + " × " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " ×  " + second_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  // 乘整数
  $("#btn_decimal_multiple_integer").click(function(){
    do{ 
      var multiple_times = [10, 100];
      var multiple_times_index_1 = Math.floor(Math.random()*multiple_times.length);
      var multiple_time_1 = multiple_times[multiple_times_index_1];
      do{
      first_number_ready = Math.floor(Math.random()*99)+1;
      }while(first_number_ready%10 == 0);
      first_number = first_number_ready/multiple_time_1;
      second_number = Math.floor(Math.random()*99)+1;
      result = first_number_ready * second_number/multiple_time_1;
      horizontal_type = first_number + " × " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " ×  " + second_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  // 基本乘法
    $("#btn_decimal_multiple_basic").click(function(){
      do{
        var multiple_times = [10, 100];
        var multiple_times_index_1 = Math.floor(Math.random()*multiple_times.length);
        var multiple_time_1 = multiple_times[multiple_times_index_1];
        var multiple_times_index_2 = Math.floor(Math.random()*multiple_times.length);
        var multiple_time_2 = multiple_times[multiple_times_index_2];
        first_number_ready = Math.floor(Math.random()*99)+1;
        first_number = first_number_ready / multiple_time_1;
        second_number_ready = Math.floor(Math.random()*99)+1;
	second_number = second_number_ready / multiple_time_2;
        result = first_number_ready * second_number_ready / ( multiple_time_1 * multiple_time_2 );
	horizontal_type = first_number + times_sign + second_number + equals_sign;
      }while(horizontal_type == pre_horizontal_type);
      $(".par").html(function(){return horizontal_type});
      pre_horizontal_type = horizontal_type;
      last_btn = "#" + $(this).attr("id");
      $(".input_class").focus();
    });

  // 简便乘法
  $("#btn_decimal_multiple_shortcut").click(function(){
    do{
        var multiple_times = [10, 100];
        var multiple_times_index = Math.floor(Math.random()*multiple_times.length);
        var multiple_time = multiple_times[multiple_times_index];
    var question_type = Math.floor(Math.random()*5);
    switch (question_type)
    {
    case 0:                    // 两数相乘的简便计算
      var temp_result_1 = (Math.floor(Math.random()*9)+1)*100;
      var temp_result_2 = Math.floor(Math.random()*4)+1;
      second_number = temp_result_1 + temp_result_2;
      first_number =  Math.floor(Math.random()*90)+10;
      result = first_number * second_number;

      first_number = first_number / multiple_time;
      second_number = second_number / multiple_time;
      result = result / (multiple_time * multiple_time );
      
      var choose = Math.floor(Math.random()*2)+1;
      switch(choose)
      {
      case 1:
         horizontal_type =  first_number + times_sign + second_number + equals_sign;
      break;
      case 2:
         horizontal_type =  second_number + times_sign + first_number + equals_sign;
      break;
      };
    break;
    case 1:                // 三个数相乘的简便计算
      var temp_result = (Math.floor(Math.random()*8)+2)*100;
      do{
        first_number = Math.floor(Math.random()*90)+10;
        var fail_flag = false;
	if(first_number%10 == 0){fail_flag = true;};
        if(first_number%5 == 0){fail_flag = true;};
      }while(fail_flag == true);
      do{
        second_number = Math.floor(Math.random()*8)+2;
        third_number = temp_result / second_number;
        var fail_flag = false;
	if(third_number%100 == 0){fail_flag = true;};
        if(Math.floor(third_number) != third_number){fail_flag = true;};
      }while( fail_flag == true);
      result = first_number * second_number * third_number;

      first_number = first_number / multiple_time;
      second_number = second_number / multiple_time;
      third_number = third_number / multiple_time;
      result = result / (multiple_time * multiple_time * multiple_time);
      
      var choose = Math.floor(Math.random()*2)+1;
      switch(choose)
      {
      case 1:
         horizontal_type = first_number + times_sign + second_number + times_sign + third_number + equals_sign;
      break;
      case 2:
         horizontal_type = second_number + times_sign + first_number + times_sign + third_number + equals_sign;
      break;
      }
    break;
    case 2:               // 四个数相乘的简便计算
      var temp_result = (Math.floor(Math.random()*90)+10)*10;
      first_number = Math.floor(Math.random()*(temp_result-1))+1;
      second_number = temp_result - first_number;
      third_number =  Math.floor(Math.random()*90)+10;
      result = temp_result * third_number;

      first_number = first_number / multiple_time;
      second_number = second_number / multiple_time;
      third_number = third_number / multiple_time;
      result = result / (multiple_time * multiple_time );
      
      var choose = Math.floor(Math.random()*3)+1;
      switch(choose)
      {
      case 1:
         horizontal_type = first_number + times_sign + third_number + plus_sign + second_number + times_sign + third_number + equals_sign;
      break;
      case 2:
         horizontal_type = first_number + times_sign + third_number + plus_sign + third_number + times_sign + second_number + equals_sign;
      break;
      case 3:
         horizontal_type = third_number + times_sign + first_number + plus_sign + third_number + times_sign + second_number + equals_sign;
      break;
      case 4:
         horizontal_type = third_number + times_sign + first_number + plus_sign + second_number + times_sign + third_number + equals_sign;
      break;
     }
    break;
      case 3:                  // 乘法和加法
        first_number = Math.floor(Math.random()*89)+11;
	var temp_result_1 = (Math.floor(Math.random()*9)+1)*100;
        second_number = Math.floor(Math.random()*(temp_result_1-1))+1;
        third_number = temp_result_1 - second_number;
	result = first_number * temp_result_1;

        first_number = first_number / multiple_time;
        second_number = second_number / multiple_time;
        third_number = third_number / multiple_time;
        result = result / (multiple_time * multiple_time);
      
        if(third_number == 1){
	  var question_type_1 = Math.floor(Math.random()*2)+1;
          if(question_type_1 == 1){
            horizontal_type = first_number + times_sign + second_number + plus_sign + first_number + equals_sign;
	  }else{
            horizontal_type = first_number + plus_sign + first_number + times_sign + second_number + equals_sign;
	  };
        }else{
	var question_type_1 = Math.floor(Math.random()*2)+1;
        switch (question_type_1)
        {
        case 1:
          horizontal_type = first_number + times_sign + second_number + plus_sign + first_number +times_sign + third_number + equals_sign;
          // horizontal_type = first_number + times_sign + second_number + plus_sign + first_number +times_sign + third_number + equals_sign + result;
        break;
	case 2:
          horizontal_type = second_number + times_sign + first_number + plus_sign + first_number +times_sign + third_number + equals_sign;
          // horizontal_type = second_number + times_sign + first_number + plus_sign + first_number +times_sign + third_number + equals_sign + result;
	break;
	case 3:
          horizontal_type = first_number + times_sign + second_number + plus_sign + third_number +times_sign + first_number + equals_sign;
          // horizontal_type = first_number + times_sign + second_number + plus_sign + third_number +times_sign + first_number + equals_sign + result;
	break;
	case 4:
          horizontal_type = second_number + times_sign + first_number + plus_sign + third_number +times_sign + first_number + equals_sign;
          // horizontal_type = second_number + times_sign + first_number + plus_sign + third_number +times_sign + first_number + equals_sign + result;
	break;
	}
	}
      break;
      case 4:                     // 乘法和减法
        first_number = Math.floor(Math.random()*89)+11;
	var temp_result_1 = (Math.floor(Math.random()*9)+1)*100;
        third_number = Math.floor(Math.random()*(99-1))+1;
        second_number = temp_result_1 + third_number;
	result = first_number * temp_result_1;

      first_number = first_number / multiple_time;
      second_number = second_number / multiple_time;
      third_number = third_number / multiple_time;
      result = result / (multiple_time * multiple_time);
      
        if(third_number == 1){
          horizontal_type = first_number + times_sign + second_number + minus_sign + first_number + equals_sign;
        }else{
	var question_type_1 = Math.floor(Math.random()*2)+1;
        switch (question_type_1)
        {
        case 1:              // a*b-a*c
          horizontal_type = first_number + times_sign + second_number + minus_sign + first_number +times_sign + third_number + equals_sign;
        break;
	case 2:             // b*a-a*c
          horizontal_type = second_number + times_sign + first_number + minus_sign + first_number +times_sign + third_number + equals_sign;
	break;
	case 3:             // a*b-c*a
          horizontal_type = first_number + times_sign + second_number + minus_sign + third_number +times_sign + first_number + equals_sign;
	break;
	case 4:            // b*a-c*a
          horizontal_type = second_number + times_sign + first_number + minus_sign + third_number +times_sign + first_number + equals_sign;
	break;
	};
	};
      break;
    };
    }while(horizontal_type == pre_horizontal_type);
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 二十三单元：小数除法
  // 整数够除
  $("#btn_decimal_divide_integer_1").click(function(){
    var multiple_time_1 = 10;
    do{
      second_number = Math.floor(Math.random()*19)+1;
    }while(second_number%10 == 0);
    var temp_result = 0
    do{
      do{
        var temp_result = Math.floor(Math.random()*89)+11;
        first_number = temp_result * second_number;
      }while(first_number%10 == 0);
      first_number = first_number / multiple_time_1;
      result = temp_result / multiple_time_1;
      horizontal_type = first_number + " ÷ " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " ÷  " + second_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  // 整数商0
  $("#btn_decimal_divide_integer_0").click(function(){
    var multiple_time_1 = 100;
    do{
    second_number = Math.floor(Math.random()*98)+2;
    }while(second_number%10 == 0);
    var temp_result = 0
    do{
      do{
        var temp_result = Math.floor(Math.random()*89)+11;
        first_number = temp_result * second_number;
      }while(first_number%10 == 0);
      first_number = first_number / multiple_time_1;
      result = temp_result / multiple_time_1;
      horizontal_type = first_number + " ÷ " + second_number + " = ";
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = first_number + " ÷  " + second_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  // 尾部添0
  $("#btn_decimal_divide_integer_tail").click(function(){
    do{
      var multiple_times = [10, 100, 1000];
      var multiple_times_index_1 = Math.floor(Math.random()*multiple_times.length);
      var multiple_time_1 = multiple_times[multiple_times_index_1];
      var temp_result = 0
      var fail_flag = false;
      do{
        do{
          second_number = Math.floor(Math.random()*98)+2;     // 第二个数不能为整十数。
        }while(second_number%10 == 0);
        do{
          temp_result = Math.floor(Math.random()*89)+11;      // 结果不能是整十数。
        }while(temp_result%10 == 0);
        first_number = temp_result * second_number;            // 第一个数必须是整十数。
      }while(first_number%10 != 0 );
      first_number = first_number / multiple_time_1;
      if(Math.round(first_number)==first_number){fail_flag = true};   // 如果第一个数不是小数，则失败
      result = temp_result / multiple_time_1;
      horizontal_type = first_number + " ÷ " + second_number + " = ";
      if(horizontal_type == pre_horizontal_type){fail_flag = true};   // 如果这个式子和前个式子一样，则失败
    }while(fail_flag == true);
    // horizontal_type = first_number + " ÷  " + second_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  // 一个数除以小数
  $("#btn_decimal_divide_decimal").click(function(){
    var multiple_times = [10, 100];
    var multiple_times_index_1 = Math.floor(Math.random()*multiple_times.length);
    var multiple_time_1 = multiple_times[multiple_times_index_1];
    second_number_ready = Math.floor(Math.random()*99)+1;
    second_number = second_number_ready / multiple_time_1;  // 第二个数一定是小数
    var temp_result = 0;
    do{
      var fail_flag = false;
      var multiple_times_2 = [1, 10, 100];
      var multiple_times_index_2 = Math.floor(Math.random()*multiple_times_2.length);
      var multiple_time_2 = multiple_times_2[multiple_times_index_2];
      result_ready = Math.floor(Math.random()*98)+2;
      result = result_ready / multiple_time_2;    // 结果，可以是整数，也可以是小数
      first_number = result_ready * second_number_ready / (multiple_time_1 * multiple_time_2);
      if(first_number == second_number){fail_flag = true};                   // 被除数和除数不等
      if(horizontal_type == pre_horizontal_type){fail_flag = true};
      horizontal_type = first_number + " ÷ " + second_number + " = ";
    }while(fail_flag == true);
    // horizontal_type = first_number + " ÷  " + second_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  // 除数更多小数位
  $("#btn_decimal_divide_decimal_more").click(function(){
    do{
      var multiple_times = [100, 1000];
      var multiple_times_index_1 = Math.floor(Math.random()*multiple_times.length);
      var multiple_time_1 = multiple_times[multiple_times_index_1];
      second_number_ready = Math.floor(Math.random()*999)+1;
      second_number = second_number_ready / multiple_time_1;  // 第二个数一定是小数
      var temp_result = 0;
      var fail_flag = false;
      var multiple_times_2 = [10, 100];
      var multiple_times_index_2 = Math.floor(Math.random()*multiple_times_2.length);
      var multiple_time_2 = multiple_times_2[multiple_times_index_2];
      result_ready = Math.floor(Math.random()*98)+2;
      result = result_ready * multiple_time_2;    // 结果，可以是整数，也可以是小数
      first_number = result_ready * second_number_ready  * multiple_time_2/ multiple_time_1;
      if(first_number == second_number){fail_flag = true};                   // 被除数和除数不等
      if(Math.round(first_number) == first_number){fail_flag = true};                   // 被除数和除数不等
      if(horizontal_type == pre_horizontal_type){fail_flag = true};
      horizontal_type = first_number + " ÷ " + second_number + " = ";
    }while(fail_flag == true);
    // horizontal_type = first_number + " ÷  " + second_number + " = " + result;
    $(".par").html(function(){return horizontal_type});
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  // 二十四单元：分数的加法和减法（一）
  // 同分母加法（真分数，分母20以内）
  $("#btn_fraction_same_denominator_add").click(function(){
    do{
      var denominator = Math.floor(Math.random()*18)+2;
      var first_numerator =  Math.floor(Math.random()*(denominator-1)+1);
      var second_numerator =  Math.floor(Math.random()*(denominator-1)+1);
      var result_numerator = first_numerator + second_numerator;
      // 分数可视化
      transfer_fraction_result(0, result_numerator, denominator);
      first_number = "f" + "0" + "," + first_numerator.toString() + "," + denominator.toString();
      second_number = "f" + "0" + "," + second_numerator.toString() + "," + denominator.toString();
      horizontal_type = [first_number, "+", second_number, "="];
      // horizontal_type = [first_number, "+", second_number, "=", result]; //测试运算结果。
    }while(horizontal_type == pre_horizontal_type);
    // 转换分数格式，方便用户输入
    transfer_result_fraction_for_input();
    // 计算cavas的长度，获取字体高度，生成绘图区
    ht_length_cal();
    var font_size = $(".par").css("font-size");
    font_size = font_size.replace("px", "");
    var canvas_height = font_size*2;
    var canvas_width = Math.ceil(ht_length*canvas_height/3);
    var canvas_html = "<canvas id=\"canvas_24\" width=\"" + canvas_width + "\" height=\"" + canvas_height + "\" style=\"vertical-align: middle;\"> 您的浏览器不支持 HTML5 canvas 标签。</canvas>" 
    $("#par_unit_24").html(canvas_html);
    // 输出横式
    draw_fraction("#canvas_24");
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 同分母减法（真分数，分母20以内）
  $("#btn_fraction_same_denominator_subtract").click(function(){
    do{
      var denominator = Math.floor(Math.random()*18)+2;
      var first_numerator =  Math.floor(Math.random()*(denominator-1)+1);
      var second_numerator =  Math.floor(Math.random()*(first_numerator)+1);
      var result_numerator = first_numerator - second_numerator;
      // 分数可视化处理
      transfer_fraction_result(0, result_numerator, denominator);
      first_number = "f" + "0" + "," + first_numerator.toString() + "," + denominator.toString();
      second_number = "f" + "0" + "," + second_numerator.toString() + "," + denominator.toString();
      horizontal_type = [first_number, "-", second_number, "="];
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = [first_number, "-", second_number, "=", result]; //测试运算结果。
    // 转换分数格式，方便用户输入
    transfer_result_fraction_for_input();
    // 计算cavas的长度，获取字体高度，生成绘图区
    ht_length_cal();
    var font_size = $(".par").css("font-size");
    font_size = font_size.replace("px", "");
    var canvas_height = font_size*2;
    var canvas_width = Math.ceil(ht_length*canvas_height/3);
    var canvas_html = "<canvas id=\"canvas_24\" width=\"" + canvas_width + "\" height=\"" + canvas_height + "\" style=\"vertical-align: middle;\"> 您的浏览器不支持 HTML5 canvas 标签。</canvas>" 
    $("#par_unit_24").html(canvas_html);
    // 输出横式
    draw_fraction("#canvas_24");
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 同分母连加减（真分数，分母20以内）
  $("#btn_fraction_same_denominator_serial_add_subtract").click(function(){
    var set_top_number = 20;
    var denominator = Math.floor(Math.random()*(set_top_number-2))+2;  // 分母在20以内
    // 选择连加或连减
    var operator_index = Math.floor(Math.random()*2);
    if (operator_index == 0){          // 连加
      //20以内连加法 
      do{
        first_numerator = Math.floor(Math.random()*(denominator-1))+1;
        second_numerator = Math.floor(Math.random()*(denominator-1))+1;
        third_numerator = Math.floor(Math.random()*(denominator-1))+1;
        result_numerator = first_numerator + second_numerator + third_numerator;
        // 分数可视化处理
        transfer_fraction_result(0, result_numerator, denominator);
        first_number = "f" + "0" + "," + first_numerator.toString() + "," + denominator.toString();
        second_number = "f" + "0" + "," + second_numerator.toString() + "," + denominator.toString();
        third_number = "f" + "0" + "," + third_numerator.toString() + "," + denominator.toString();
        horizontal_type = [first_number, "+", second_number, "+", third_number, "="];
        // horizontal_type = [first_number, "+", second_number, "+", third_number, "=", + result];  // 测试计算结果
      }while(horizontal_type == pre_horizontal_type);
    }else{                         // 连减
    // 20以内的三个数连减运算
      do{
        first_numerator = Math.floor(Math.random()*denominator)+2;
        second_numerator = Math.floor(Math.random()*(first_numerator-2))+1;
        third_numerator = Math.floor(Math.random()*(first_numerator - second_numerator)) + 1;
        result_numerator = first_numerator - second_numerator - third_numerator;
        // 分数可视化处理
        transfer_fraction_result(0, result_numerator, denominator);
        first_number = "f" + "0" + "," + first_numerator.toString() + "," + denominator.toString();
        second_number = "f" + "0" + "," + second_numerator.toString() + "," + denominator.toString();
        third_number = "f" + "0" + "," + third_numerator.toString() + "," + denominator.toString();
        horizontal_type = [first_number, "-", second_number, "-", third_number, "="];
        // horizontal_type = [first_number, "+", second_number, "+", third_number, "=", + result];  // 测试计算结果
      }while(horizontal_type == pre_horizontal_type);
    };
    // 转换分数格式，方便用户输入
    transfer_result_fraction_for_input();
    // 计算cavas的长度，获取字体高度，生成绘图区
    ht_length_cal();
    var font_size = $(".par").css("font-size");
    font_size = font_size.replace("px", "");
    var canvas_height = font_size*2;
    var canvas_width = Math.ceil(ht_length*canvas_height/3);
    var canvas_html = "<canvas id=\"canvas_24\" width=\"" + canvas_width + "\" height=\"" + canvas_height + "\" style=\"vertical-align: middle;\"> 您的浏览器不支持 HTML5 canvas 标签。</canvas>" 
    $("#par_unit_24").html(canvas_html);
    // 输出横式
    draw_fraction("#canvas_24");
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  // 异分母加法（真分数，分母10以内）
  $("#btn_fraction_diff_denominator_add").click(function(){
    do{
      var first_denominator = Math.floor(Math.random()*8)+2;
      do{
        var second_denominator = Math.floor(Math.random()*8)+2;
      }while(second_denominator == first_denominator);
      var first_numerator =  Math.floor(Math.random()*(first_denominator-1)+1);
      var second_numerator =  Math.floor(Math.random()*(second_denominator-1)+1);
      var result_numerator = Math.round(first_numerator*second_denominator) + Math.round(second_numerator*first_denominator);
      var result_denominator = Math.round(first_denominator * second_denominator);
      // 分数可视化
      transfer_fraction_result(0, result_numerator, result_denominator);
      first_number = "f" + "0" + "," + first_numerator.toString() + "," + first_denominator.toString();
      second_number = "f" + "0" + "," + second_numerator.toString() + "," + second_denominator.toString();
      horizontal_type = [first_number, "+", second_number, "="];
    }while(horizontal_type == pre_horizontal_type);
    // horizontal_type = [first_number, "+", second_number, "=", result]; //测试运算结果。
    // 转换分数格式，方便用户输入
    transfer_result_fraction_for_input();
    // 计算cavas的长度，获取字体高度，生成绘图区
    ht_length_cal();
    var font_size = $(".par").css("font-size");
    font_size = font_size.replace("px", "");
    var canvas_height = font_size*2;
    var canvas_width = Math.ceil(ht_length*canvas_height/3);
    var canvas_html = "<canvas id=\"canvas_24\" width=\"" + canvas_width + "\" height=\"" + canvas_height + "\" style=\"vertical-align: middle;\"> 您的浏览器不支持 HTML5 canvas 标签。</canvas>" 
    $("#par_unit_24").html(canvas_html);
    // 输出横式
    draw_fraction("#canvas_24");
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 异分母减法（真分数，分母10以内）
  $("#btn_fraction_diff_denominator_subtract").click(function(){
    do{
      var first_denominator = Math.floor(Math.random()*7)+2;
      var first_numerator =  Math.floor(Math.random()*(first_denominator-1)+1);
      do{
        var second_denominator = Math.floor(Math.random()*8)+2;
        var second_numerator =  Math.floor(Math.random()*(second_denominator-1)+1);
        var result_numerator = Math.round(first_numerator*second_denominator) - Math.round(second_numerator*first_denominator);
      }while(second_denominator == first_denominator || result_numerator < 0);
      var result_denominator = Math.round(first_denominator * second_denominator);
      // 分数可视化
      transfer_fraction_result(0, result_numerator, result_denominator);
      first_number = "f" + "0" + "," + first_numerator.toString() + "," + first_denominator.toString();
      second_number = "f" + "0" + "," + second_numerator.toString() + "," + second_denominator.toString();
      horizontal_type = [first_number, "-", second_number, "="];
    }while(horizontal_type == pre_horizontal_type);
    //horizontal_type = [first_number, "-", second_number, "=", result]; //测试运算结果。
    // 转换分数格式，方便用户输入
    transfer_result_fraction_for_input();
    // 计算cavas的长度，获取字体高度，生成绘图区
    ht_length_cal();
    var font_size = $(".par").css("font-size");
    font_size = font_size.replace("px", "");
    var canvas_height = font_size*2;
    var canvas_width = Math.ceil(ht_length*canvas_height/3);
    var canvas_html = "<canvas id=\"canvas_24\" width=\"" + canvas_width + "\" height=\"" + canvas_height + "\" style=\"vertical-align: middle;\"> 您的浏览器不支持 HTML5 canvas 标签。</canvas>" 
    $("#par_unit_24").html(canvas_html);
    // 输出横式
    draw_fraction("#canvas_24");
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 二十四单元：分数的加法和减法（二）
  //不带括号混合（真分数，20以内）
  $("#btn_fraction_3_step").click(function(){
    var temp_result =0;
    var operators=[" + ", " - "];
    var operator_index = Math.floor(Math.random()*operators.length);
    var first_operator = operators[operator_index];
    operators.splice(operator_index, 1);
    do{
    if (first_operator == " + "){
      var first_denominator = Math.floor(Math.random()*8)+2;
      var first_numerator =  Math.floor(Math.random()*(first_denominator-1)+1);
      var second_denominator = Math.floor(Math.random()*8)+2;
      var second_numerator =  Math.floor(Math.random()*(second_denominator-1)+1);
      var temp_result = first_numerator/first_denominator + second_numerator/second_denominator;
      do{
        var third_denominator = Math.floor(Math.random()*8)+2;
        var third_numerator =  Math.floor(Math.random()*(third_denominator-1)+1);
      }while(third_numerator/third_denominator > temp_result);
      var result_numerator = Math.round(first_numerator*second_denominator*third_denominator) + Math.round(second_numerator*first_denominator*third_denominator)-Math.round(third_numerator*first_denominator*second_denominator);
      var result_denominator = Math.round(first_denominator * second_denominator * third_denominator);
      // 分数可视化
      transfer_fraction_result(0, result_numerator, result_denominator);
      first_number = "f" + "0" + "," + first_numerator.toString() + "," + first_denominator.toString();
      second_number = "f" + "0" + "," + second_numerator.toString() + "," + second_denominator.toString();
      third_number = "f" + "0" + "," + third_numerator.toString() + "," + third_denominator.toString();
      horizontal_type = [first_number, "+", second_number, "-", third_number, "="];
      // horizontal_type = [first_number, "+", second_number, "-", third_number, "=", result];  // 测试结果
    }else{
      do{
        var first_denominator = Math.floor(Math.random()*8)+2;
        var first_numerator =  Math.floor(Math.random()*(first_denominator-1)+1);
        var second_denominator = Math.floor(Math.random()*8)+2;
        var second_numerator =  Math.floor(Math.random()*(second_denominator-1)+1);
      }while(first_numerator/first_denominator < second_numerator/second_denominator);
      var third_denominator = Math.floor(Math.random()*8)+2;
      var third_numerator =  Math.floor(Math.random()*(third_denominator-1)+1);
      var result_numerator = Math.round(first_numerator*second_denominator*third_denominator) - Math.round(second_numerator*first_denominator*third_denominator) + Math.round(third_numerator*first_denominator*second_denominator);
      var result_denominator = Math.round(first_denominator * second_denominator * third_denominator);
      // 分数可视化
      transfer_fraction_result(0, result_numerator, result_denominator);
      first_number = "f" + "0" + "," + first_numerator.toString() + "," + first_denominator.toString();
      second_number = "f" + "0" + "," + second_numerator.toString() + "," + second_denominator.toString();
      third_number = "f" + "0" + "," + third_numerator.toString() + "," + third_denominator.toString();
      horizontal_type = [first_number, "-", second_number, "+", third_number, "="];
      // horizontal_type = [first_number, "-", second_number, "+", third_number, "=", result];  // 测试结果
    };
    }while(horizontal_type == pre_horizontal_type);
    // 转换分数格式，方便用户输入
    transfer_result_fraction_for_input();
    // 计算cavas的长度，获取字体高度，生成绘图区
    ht_length_cal();
    var font_size = $(".par").css("font-size");
    font_size = font_size.replace("px", "");
    var canvas_height = font_size*2;
    var canvas_width = Math.ceil(ht_length*canvas_height/3);
    var canvas_html = "<canvas id=\"canvas_24_2\" width=\"" + canvas_width + "\" height=\"" + canvas_height + "\" style=\"vertical-align: middle;\"> 您的浏览器不支持 HTML5 canvas 标签。</canvas>" 
    $("#par_unit_24_2").html(canvas_html);
    // 输出横式
    draw_fraction("#canvas_24_2");
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  //带括号混合（真分数，20以内）
  // 和之前一样充满煎熬。这回决定abc四种方式都加上括号来测试。
  // 这么决定或许有些令人费解。前面可都是坚持“必要性原则”来安排括号。
  $("#btn_fraction_3_step_with_brackets").click(function(){
    var temp_result =0;
    var operators=[" + ", " - "];
    var operator_index = Math.floor(Math.random()*operators.length);
    var first_operator = operators[operator_index];
    operators.splice(operator_index, 1);
    do{
    if (first_operator == " + "){
      var second_operator = Math.floor(Math.random()*2);
      if(second_operator == 0){         // a + ( b - c);
      var first_denominator = Math.floor(Math.random()*8)+2;
      var first_numerator =  Math.floor(Math.random()*(first_denominator-1)+1);
      var second_denominator = Math.floor(Math.random()*8)+2;
      var second_numerator =  Math.floor(Math.random()*(second_denominator-1)+1);
      do{
        var third_denominator = Math.floor(Math.random()*8)+2;
        var third_numerator =  Math.floor(Math.random()*(third_denominator-1)+1);
      }while(third_numerator/third_denominator > second_numerator/second_denominator);
      var result_numerator = Math.round(first_numerator*second_denominator*third_denominator) + Math.round(second_numerator*first_denominator*third_denominator)-Math.round(third_numerator*first_denominator*second_denominator);
      var result_denominator = Math.round(first_denominator * second_denominator * third_denominator);
      // 分数可视化
      transfer_fraction_result(0, result_numerator, result_denominator);
      first_number = "f" + "0" + "," + first_numerator.toString() + "," + first_denominator.toString();
      second_number = "f" + "0" + "," + second_numerator.toString() + "," + second_denominator.toString();
      third_number = "f" + "0" + "," + third_numerator.toString() + "," + third_denominator.toString();
      horizontal_type = [first_number, "+", "(", second_number, "-", third_number, ")", "="];
      // horizontal_type = [first_number, "+", "(", second_number, "-", third_number, ")",  "=", result];  // 测试结果
    }else{                     // a + ( b + c )
      var first_denominator = Math.floor(Math.random()*8)+2;
      var first_numerator =  Math.floor(Math.random()*(first_denominator-1)+1);
      var second_denominator = Math.floor(Math.random()*8)+2;
      var second_numerator =  Math.floor(Math.random()*(second_denominator-1)+1);
      var temp_result = first_numerator/first_denominator + second_numerator/second_denominator;
      var third_denominator = Math.floor(Math.random()*8)+2;
      var third_numerator =  Math.floor(Math.random()*(third_denominator-1)+1);
      var result_numerator = Math.round(first_numerator*second_denominator*third_denominator) + Math.round(second_numerator*first_denominator*third_denominator)  + Math.round(third_numerator*first_denominator*second_denominator);
      var result_denominator = Math.round(first_denominator * second_denominator * third_denominator);
      // 分数可视化
      transfer_fraction_result(0, result_numerator, result_denominator);
      first_number = "f" + "0" + "," + first_numerator.toString() + "," + first_denominator.toString();
      second_number = "f" + "0" + "," + second_numerator.toString() + "," + second_denominator.toString();
      third_number = "f" + "0" + "," + third_numerator.toString() + "," + third_denominator.toString();
      horizontal_type = [first_number, "+", "(", second_number, "+", third_number, ")", "="];
      // horizontal_type = [first_number, "+", "(", second_number, "+", third_number, ")", "=", result];  // 测试结果
    };
    }else{
      var second_operator = Math.floor(Math.random()*2);
      if(second_operator == 0){         // a - ( b - c);
      do{
        var second_denominator = Math.floor(Math.random()*8)+2;
        var second_numerator =  Math.floor(Math.random()*(second_denominator-1)+1);
        var third_denominator = Math.floor(Math.random()*8)+2;
        var third_numerator =  Math.floor(Math.random()*(third_denominator-1)+1);
      }while(third_numerator/third_denominator > second_numerator/second_denominator);
      var temp_numerator = Math.round(second_numerator*third_denominator) - Math.round(third_numerator*second_denominator);
      var temp_denominator = Math.round(second_denominator * third_denominator);
      do{
        var first_denominator = Math.floor(Math.random()*8)+2;
        var first_numerator =  Math.floor(Math.random()*(first_denominator-1)+1);
      }while(first_numerator/first_denominator < temp_numerator/temp_denominator);
      var result_numerator = Math.round(first_numerator*second_denominator*third_denominator) - Math.round(second_numerator*first_denominator*third_denominator) + Math.round(third_numerator*first_denominator*second_denominator);
      var result_denominator = Math.round(first_denominator * second_denominator * third_denominator);
      // 分数可视化
      transfer_fraction_result(0, result_numerator, result_denominator);
      first_number = "f" + "0" + "," + first_numerator.toString() + "," + first_denominator.toString();
      second_number = "f" + "0" + "," + second_numerator.toString() + "," + second_denominator.toString();
      third_number = "f" + "0" + "," + third_numerator.toString() + "," + third_denominator.toString();
      horizontal_type = [first_number, "-", "(", second_number, "-", third_number, ")", "="];
      // horizontal_type = [first_number, "-", "(", second_number, "-", third_number, ")", "=", result];  // 测试结果
    }else{                                     // a - ( b + c );
      do{
      var first_denominator = Math.floor(Math.random()*5)+2;
      var first_numerator =  Math.floor(Math.random()*(first_denominator-1)+1);
      var first_number_ready = first_numerator/first_denominator;
        do{
          var second_denominator = Math.floor(Math.random()*(11-first_denominator))+first_denominator;
          var second_numerator =  Math.floor(Math.random()*(first_numerator-1)+1);
	  var second_number_ready = second_numerator/second_denominator;
        }while(first_number_ready < second_number_ready);
        do{
          var third_denominator = Math.floor(Math.random()*(11-first_denominator))+first_denominator;
          var third_numerator =  Math.floor(Math.random()*(first_numerator-1)+1);
          var third_number_ready = third_numerator/third_denominator;
        }while(first_number_ready < third_number_ready);
        var temp_numerator = Math.round(second_numerator*third_denominator) + Math.round(third_numerator*second_denominator);
        var temp_denominator = Math.round(second_denominator * third_denominator);
      }while(first_numerator/first_denominator < temp_numerator/temp_denominator);
      var result_numerator = Math.round(first_numerator*second_denominator*third_denominator) - Math.round(second_numerator*first_denominator*third_denominator) - Math.round(third_numerator*first_denominator*second_denominator);
      var result_denominator = Math.round(first_denominator * second_denominator * third_denominator);
      // 分数可视化
      transfer_fraction_result(0, result_numerator, result_denominator);
      first_number = "f" + "0" + "," + first_numerator.toString() + "," + first_denominator.toString();
      second_number = "f" + "0" + "," + second_numerator.toString() + "," + second_denominator.toString();
      third_number = "f" + "0" + "," + third_numerator.toString() + "," + third_denominator.toString();
      horizontal_type = [first_number, "-", "(", second_number, "+", third_number, ")", "="];
      // horizontal_type = [first_number, "-", "(", second_number, "+", third_number, ")", "=", result];  // 测试结果
    };
    };
    }while(horizontal_type == pre_horizontal_type);
    // 转换分数格式，方便用户输入
    transfer_result_fraction_for_input();
    // 计算cavas的长度，获取字体高度，生成绘图区
    ht_length_cal();
    var font_size = $(".par").css("font-size");
    font_size = font_size.replace("px", "");
    var canvas_height = font_size*2;
    var canvas_width = Math.ceil(ht_length*canvas_height/3);
    var canvas_html = "<canvas id=\"canvas_24_2\" width=\"" + canvas_width + "\" height=\"" + canvas_height + "\" style=\"vertical-align: middle;\"> 您的浏览器不支持 HTML5 canvas 标签。</canvas>" 
    $("#par_unit_24_2").html(canvas_html);
    // 输出横式
    draw_fraction("#canvas_24_2");
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  //运算定律和简便运算
  $("#btn_fraction_add_subtract_shortcut").click(function(){
    do{
      var shortcut_type = Math.floor(Math.random()*4);
      switch (shortcut_type)
      {
      case 0: //加法运算定律的应用（三个加数）
        var first_denominator = Math.floor(Math.random()*8)+2;
        var first_numerator =  Math.floor(Math.random()*(first_denominator-1)+1);
        do{
        var second_denominator = Math.floor(Math.random()*8)+2;
        }while(first_denominator == second_denominator);
        var second_numerator =  Math.floor(Math.random()*(second_denominator-1)+1);
        var third_denominator = first_denominator;
        var third_numerator =  first_denominator - first_numerator;
        var result_numerator = second_denominator + second_numerator;
        var result_denominator = second_denominator;
        // 分数可视化
        transfer_fraction_result(0, result_numerator, result_denominator);
        first_number = "f" + "0" + "," + first_numerator.toString() + "," + first_denominator.toString();
        second_number = "f" + "0" + "," + second_numerator.toString() + "," + second_denominator.toString();
        third_number = "f" + "0" + "," + third_numerator.toString() + "," + third_denominator.toString();
  
        horizontal_type = [first_number, "+", second_number, "+", third_number, "="];
        // horizontal_type = [first_number, "+", second_number, "+", third_number, "=", result];
      break;
      case 1: //加法运算定律的应用（四个加数）
        var first_denominator = Math.floor(Math.random()*8)+2;
        var first_numerator =  Math.floor(Math.random()*(first_denominator-1)+1);
        do{
          var second_denominator = Math.floor(Math.random()*8)+2;
        }while(first_denominator == second_denominator);
        var second_numerator =  Math.floor(Math.random()*(second_denominator-1)+1);
        var third_denominator = first_denominator;
        var third_numerator =  first_denominator - first_numerator;
        var fourth_denominator = second_denominator;
        var fourth_numerator =  Math.floor(Math.random()*(second_denominator-1)+1);
        var result_numerator = second_denominator + second_numerator + fourth_numerator;
        var result_denominator = second_denominator;
        // 分数可视化
        transfer_fraction_result(0, result_numerator, result_denominator);
        first_number = "f" + "0" + "/" + first_numerator.toString() + "/" + first_denominator.toString();
        second_number = "f" + "0" + "/" + second_numerator.toString() + "/" + second_denominator.toString();
        third_number = "f" + "0" + "/" + third_numerator.toString() + "/" + third_denominator.toString();
        fourth_number = "f" + "0" + "/" + fourth_numerator.toString() + "/" + fourth_denominator.toString();

        var shuffle_num=[first_number, second_number, third_number, fourth_number];
        for(var j, x, i = shuffle_num.length;
          i; 
	  j = parseInt(Math.random() * i), 
	  x = shuffle_num[--i], 
	  shuffle_num[i] = shuffle_num[j], 
	  shuffle_num[j] = x);
  
	  for(var i=0; i<shuffle_num.length; i++){
	    shuffle_num[i] = shuffle_num[i].toString().replace(/\//g, ",");
	  };
  
        horizontal_type = [shuffle_num[0], "+", shuffle_num[1], "+", shuffle_num[2], "+", shuffle_num[3], "="];
        // horizontal_type = [shuffle_num[0], "+", shuffle_num[1], "+", shuffle_num[2], "+", shuffle_num[3], "=", result];
      break;
    case 2: // 连减
    var question_type = Math.floor(Math.random()*2)+1;
    switch (question_type)
    {
    case 1:                    // 后两个减数交换，如137-25-37
      var first_integer = Math.floor(Math.random()*2)+1;
      var first_denominator = Math.floor(Math.random()*8)+2;
      var first_numerator =  Math.floor(Math.random()*(first_denominator-1)+1);
      do{
        var second_denominator = Math.floor(Math.random()*8)+2;
      }while(first_denominator == second_denominator);
      var second_numerator =  Math.floor(Math.random()*(second_denominator-1)+1);
      var third_denominator = first_denominator;
      var third_numerator = first_numerator;
      var result_numerator = Math.round(second_denominator * first_integer - second_numerator);
      var result_denominator = second_denominator;
      // 分数可视化
      transfer_fraction_result(0, result_numerator, result_denominator);
      first_number = "f" + first_integer + "," + first_numerator.toString() + "," + first_denominator.toString();
      second_number = "f" + "0" + "," + second_numerator.toString() + "," + second_denominator.toString();
      third_number = "f" + "0" + "," + third_numerator.toString() + "," + third_denominator.toString();

      var choose = Math.floor(Math.random()*3)+1;
      switch(choose)
      {
      case 1:                 // 后两数相减 a-b-c
        horizontal_type = [first_number, "-", second_number, "-", third_number, "="];
        // horizontal_type = [first_number, "-", second_number, "-", third_number, "=", result]; //测试运算结果。
      break;
      case 2:                 // 后两数相加a-(b+c)
        horizontal_type = [first_number, "-", "(", second_number, "+", third_number, ")", "="];
        // horizontal_type = [first_number, "-", "(", second_number, "+", third_number, ")", "=", result]; //测试运算结果。
      break;
      case 3:                 // 后两数相加a-(c+b)
        horizontal_type = [first_number, "-", "(", third_number, "+", second_number, ")", "="];
        // horizontal_type = [first_number, "-", "(", third_number, "+", second_number, ")", "=", result]; //测试运算结果。
      break;
      };
    break;
    case 2:                // 后两个减数结合
      var first_integer = Math.floor(Math.random()*2)+1;
      var first_denominator = Math.floor(Math.random()*8)+2;
      var first_numerator =  Math.floor(Math.random()*(first_denominator-1)+1);
      do{
        var second_denominator = Math.floor(Math.random()*8)+2;
      }while(first_denominator == second_number);
      var second_numerator =  Math.floor(Math.random()*(second_denominator-1)+1);
      var third_denominator = second_denominator;
      var third_numerator = second_denominator - second_numerator;
      var result_integer = first_integer - 1;
      var result_numerator = first_numerator;
      var result_denominator = first_denominator;
      // 分数可视化
      transfer_fraction_result(result_integer, result_numerator, result_denominator);
      first_number = "f" + first_integer + "," + first_numerator.toString() + "," + first_denominator.toString();
      second_number = "f" + "0" + "," + second_numerator.toString() + "," + second_denominator.toString();
      third_number = "f" + "0" + "," + third_numerator.toString() + "," + third_denominator.toString();
      horizontal_type = [first_number, "-", second_number, "-", third_number, "="];
      // horizontal_type = [first_number, "-", second_number, "-", third_number, "=", result]; //测试运算结果。
    break;
    };
    break;
    case 3: // 加减
    var operators_num = 3;//Math.floor(Math.random()*2)+2;
    switch (operators_num)
    {
    case 2:                    // 两个操作符三个数的加减简便运算
      var question_type = Math.floor(Math.random()*3)+1;
      switch (question_type)
      {
      case 1:                    // a-b+c=a+c-b;  还想做一个a-b+c=a-(b-c)，就是不知道加括号会不会超出范围。
        var first_denominator = Math.floor(Math.random()*8)+2;
        var first_numerator =  Math.floor(Math.random()*(first_denominator-1)+1);
        do{
          var second_denominator = Math.floor(Math.random()*8)+2;
        }while(first_denominator == second_number);
        var second_numerator =  Math.floor(Math.random()*(second_denominator-1)+1);
        var third_denominator = first_denominator;
        var third_numerator =  first_denominator - first_numerator;
        var result_numerator = second_denominator - second_numerator;
        var result_denominator = second_denominator;
        // 分数可视化
        transfer_fraction_result(0, result_numerator, result_denominator);
        first_number = "f" + "0" + "," + first_numerator.toString() + "," + first_denominator.toString();
        second_number = "f" + "0" + "," + second_numerator.toString() + "," + second_denominator.toString();
        third_number = "f" + "0" + "," + third_numerator.toString() + "," + third_denominator.toString();
        horizontal_type =  [first_number, "-", second_number, "+", third_number, "="];
        // horizontal_type =  [first_number, "-", second_number, "+", third_number, "=", result];
      break;
      case 2:                   // a+b-c=a-c+b
        var first_integer = Math.floor(Math.random()*3);
        var first_denominator = Math.floor(Math.random()*8)+2;
        var first_numerator =  Math.floor(Math.random()*(first_denominator-1)+1);
        do{
          var second_denominator = Math.floor(Math.random()*8)+2;
        }while(first_denominator == second_number);
        var second_numerator =  Math.floor(Math.random()*(second_denominator-1)+1);
        var third_denominator = first_denominator;
        var third_numerator = first_numerator;
        var result_numerator = Math.round(second_denominator * first_integer + second_numerator);
        var result_denominator = second_denominator;
        // 分数可视化
        transfer_fraction_result(0, result_numerator, result_denominator);
        first_number = "f" + first_integer + "," + first_numerator.toString() + "," + first_denominator.toString();
        second_number = "f" + "0" + "," + second_numerator.toString() + "," + second_denominator.toString();
        third_number = "f" + "0" + "," + third_numerator.toString() + "," + third_denominator.toString();
        horizontal_type =  [first_number, "+", second_number, "-", third_number, "="];
        // horizontal_type =  [first_number, "+", second_number, "-", third_number, "=", result];
      break;
      case 3:                  // a+b-c=a+(b-c);  实现过程本质上和case 2相同。
        var first_integer = Math.floor(Math.random()*3);
        var first_denominator = Math.floor(Math.random()*8)+2;
        var first_numerator =  Math.floor(Math.random()*(first_denominator-1)+1);
        do{
          var second_denominator = Math.floor(Math.random()*8)+2;
        }while(first_denominator == second_number);
        var second_numerator =  Math.floor(Math.random()*(second_denominator-1)+1);
        var third_denominator = first_denominator;
        var third_numerator = first_numerator;
        var result_numerator = Math.round(second_denominator * first_integer + second_numerator);
        var result_denominator = second_denominator;
        // 分数可视化
        transfer_fraction_result(0, result_numerator, result_denominator);
        first_number = "f" + first_integer + "," + first_numerator.toString() + "," + first_denominator.toString();
        second_number = "f" + "0" + "," + second_numerator.toString() + "," + second_denominator.toString();
        third_number = "f" + "0" + "," + third_numerator.toString() + "," + third_denominator.toString();
        horizontal_type =  [second_number, "+", first_number, "-", third_number, "="];
        // horizontal_type =  [second_number, "+", first_number, "-", third_number, "=", result];
      break;
      }
    break;
    case 3:            // 三个操作符四个数的加减简便运算
      var question_type = Math.floor(Math.random()*3)+1;
      switch (question_type)
      {
      case 1:                    // 一个减号，两个加号
        var first_integer = Math.floor(Math.random()*3);
        var first_denominator = Math.floor(Math.random()*8)+2;
        var first_numerator =  Math.floor(Math.random()*(first_denominator-1))+1;
        var second_denominator = first_denominator;
        var second_numerator =  first_numerator;
        var third_integer = Math.floor(Math.random()*2);
        do{
          var third_denominator =  Math.floor(Math.random()*8)+2;
        }while(first_denominator == third_denominator);
        var third_numerator =  Math.floor(Math.random()*(third_denominator-1))+1;;
        var fourth_denominator = third_denominator;
        var fourth_numerator =   Math.floor(Math.random()*(fourth_denominator-1))+1;
        var result_integer = first_integer + third_integer;
        var result_numerator =  third_numerator + fourth_numerator;
        var result_denominator = third_denominator;
        // 分数可视化
        transfer_fraction_result(result_integer, result_numerator, result_denominator);
        first_number = "f" + first_integer + "," + first_numerator.toString() + "," + first_denominator.toString();
        second_number = "f" + "0" + "," + second_numerator.toString() + "," + second_denominator.toString();
        third_number = "f" + third_integer.toString() + "," + third_numerator.toString() + "," + third_denominator.toString();
        fourth_number = "f" + "0" + "," + fourth_numerator.toString() + "," + fourth_denominator.toString();
        var question_type_1 = Math.floor(Math.random()*3)+1;
        switch (question_type_1)
        {
        case 1:                    // a+c+d-b=(a-b)+(c+d)
          horizontal_type = [first_number, "+", third_number, "+", fourth_number, "-", second_number, "="];
          // horizontal_type = [first_number, "+", third_number, "+", fourth_number, "-", second_number, "=", result];
        break;
        case 2:                    // c+a+d-b=(a-b)+(c+d)
          horizontal_type = [third_number, "+", first_number, "+", fourth_number, "-", second_number, "="];
          // horizontal_type = [third_number, "+", first_number, "+", fourth_number, "-", second_number, "=", result];
        break;
        case 3:                    // c+d+a-b=(a-b)+(c+d)
          horizontal_type = [third_number, "+", fourth_number, "+", first_number, "-", second_number, "="];
          // horizontal_type = [third_number, "+", fourth_number, "+", first_number, "-", second_number, "=", result];
        break;
        };
      break;
      case 2:           // 两个减号，一个加号： (a-b)+(c-d)
        var first_integer = Math.floor(Math.random()*3);
        var first_denominator = Math.floor(Math.random()*8)+2;
        var first_numerator =  Math.floor(Math.random()*(first_denominator-1)+1);
        var second_denominator = first_denominator;
        var second_numerator =  first_numerator;
        do{
          var third_integer = Math.floor(Math.random()*2);
        }while(first_denominator == third_denominator);
        var third_denominator =  Math.floor(Math.random()*8)+2;
        var third_numerator =  Math.floor(Math.random()*(third_denominator-1)+1);;
        var fourth_denominator = third_denominator;
        var fourth_numerator =  third_numerator;
        first_number = "f" + first_integer + "," + first_numerator.toString() + "," + first_denominator.toString();
        second_number = "f" + "0" + "," + second_numerator.toString() + "," + second_denominator.toString();
        third_number = "f" + third_integer + "," + third_numerator.toString() + "," + third_denominator.toString();
        fourth_number = "f" + "0" + "," + fourth_numerator.toString() + "," + fourth_denominator.toString();
        result = first_integer + third_integer;

        var question_type_2 = Math.floor(Math.random()*3)+1;
        switch (question_type_2)
        {
        case 1:                    // a+c-d-b
          horizontal_type = [first_number, "+", third_number, "-", fourth_number, "-", second_number, "="];
          // horizontal_type = [first_number, "+", third_number, "-", fourth_number, "-", second_number, "=", result];
        break;
	case 2:                    // a-d-b+c
          horizontal_type = [first_number, "-", fourth_number, "-", second_number, "+", third_number, "="];
          // horizontal_type = [first_number, "-", fourth_number, "-", second_number, "+", third_number, "=", result];
        break;
	case 3:                    // a-d+c-b
          horizontal_type = [first_number, "-", fourth_number, "+", third_number, "-", second_number, "="];
          // horizontal_type = [first_number, "-", fourth_number, "+", third_number, "-", second_number, "=", result];
        break;
	}
      break;
      case 3:            // 两个减号，一个加号：a-b-c+d=a-(b+c)+d
      var first_integer = Math.floor(Math.random()*2)+1;
      var first_denominator = Math.floor(Math.random()*8)+2;
      var first_numerator =  Math.floor(Math.random()*(first_denominator-1)+1);
      do{
        var second_denominator = Math.floor(Math.random()*8)+2;
      }while(second_denominator == first_denominator);
      var second_numerator =  Math.floor(Math.random()*(second_denominator-1)+1);
      var third_denominator = second_denominator;
      var third_numerator = second_denominator - second_numerator;
      var fourth_denominator = first_denominator;
      var fourth_numerator = Math.floor(Math.random()*(first_denominator-1)+1);
      var result_integer = first_integer - 1;
      var result_numerator = first_numerator + fourth_numerator;
      var result_denominator = first_denominator;
      // 分数可视化
      transfer_fraction_result(result_integer, result_numerator, result_denominator);
      first_number = "f" + first_integer + "," + first_numerator.toString() + "," + first_denominator.toString();
      second_number = "f" + "0" + "," + second_numerator.toString() + "," + second_denominator.toString();
      third_number = "f" + "0" + "," + third_numerator.toString() + "," + third_denominator.toString();
      fourth_number = "f" + "0" + "," + fourth_numerator.toString() + "," + fourth_denominator.toString();

        var question_type_2 = Math.floor(Math.random()*3)+1;
        switch (question_type_2)
        {
	case 1:
          horizontal_type = [first_number, "-", third_number, "-", second_number, "+", fourth_number, "="];
          // horizontal_type = [first_number, "-", third_number, "-", second_number, "+", fourth_number, "=", result];
        break;
        case 2:
          horizontal_type = [first_number, "-", third_number, "+", fourth_number, "-", second_number, "="];
          // horizontal_type = [first_number, "-", third_number, "+", fourth_number, "-", second_number, "=", result];
        break;
        case 3:
          horizontal_type = [first_number, "+", fourth_number, "-", second_number, "-", third_number, "="];
          // horizontal_type = [first_number, "+", fourth_number, "-", second_number, "-", third_number, "=", result];
        break;
        };
      break;
      };
    break;
    };
    break;
    };
    }while(horizontal_type == pre_horizontal_type);
    // 转换分数格式，方便用户输入
    transfer_result_fraction_for_input();
    // 计算cavas的长度，获取字体高度，生成绘图区
    ht_length_cal();
    var font_size = $(".par").css("font-size");
    font_size = font_size.replace("px", "");
    var canvas_height = font_size*2;
    var canvas_width = Math.ceil(ht_length*canvas_height/3);
    var canvas_html = "<canvas id=\"canvas_24_2\" width=\"" + canvas_width + "\" height=\"" + canvas_height + "\" style=\"vertical-align: middle;\"> 您的浏览器不支持 HTML5 canvas 标签。</canvas>" 
    $("#par_unit_24_2").html(canvas_html);
    // 输出横式
    draw_fraction("#canvas_24_2");
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 二十五单元：分数的乘法
  // 分数的乘法和除法都加入了约分的内容，是不是画蛇添足了？
  // 分数乘整数
  $("#btn_fraction_multiple_integer").click(function(){
    do{ 
      var reductioners = [2, 3, 5, 7, 11, 13, 17, 19];
      var reductioner_index = Math.floor(Math.random()*reductioners.length);
      var first_reductioner = reductioners[reductioner_index];
      do{
        var first_denominator = Math.round((Math.floor(Math.random()*9)+1)*first_reductioner);
      }while(first_denominator > 20);
      var first_numerator =  Math.floor(Math.random()*(first_denominator-1)+1);
      do{
        var second_number = Math.round((Math.floor(Math.random()*9)+1)*first_reductioner);
      }while(first_denominator == second_number);
      var result_denominator = first_denominator;
      var result_numerator = Math.round(first_numerator * second_number);
      // 分数可视化
      transfer_fraction_result(0, result_numerator, result_denominator);
      first_number = "f" + "0" + "," + first_numerator.toString() + "," + first_denominator.toString();
      var multiplier_order = Math.floor(Math.random()*2);
      if(multiplier_order == 0){
        horizontal_type = [first_number, "×", second_number, "="];
        // horizontal_type = [first_number, "×", second_number, "=", result];
      }else{
        horizontal_type = [second_number, "×", first_number, "="];
        // horizontal_type = [second_number, "×", first_number, "=", result];
      };
    }while(horizontal_type == pre_horizontal_type);
    // 转换分数格式，方便用户输入
    transfer_result_fraction_for_input();
    // 计算cavas的长度，获取字体高度，生成绘图区
    ht_length_cal();
    var font_size = $(".par").css("font-size");
    font_size = font_size.replace("px", "");
    var canvas_height = font_size*2;
    var canvas_width = Math.ceil(ht_length*canvas_height/3);
    var canvas_html = "<canvas id=\"canvas_25\" width=\"" + canvas_width + "\" height=\"" + canvas_height + "\" style=\"vertical-align: middle;\"> 您的浏览器不支持 HTML5 canvas 标签。</canvas>" 
    $("#par_unit_25").html(canvas_html);
    // 输出横式
    draw_fraction("#canvas_25");
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  // 分数乘分数
  $("#btn_fraction_multiple_fraction").click(function(){
    do{ 
      var reductioners = [2, 3, 5, 7, 11, 13, 17, 19];
      var reductioner_index = Math.floor(Math.random()*reductioners.length);
      var first_reductioner = reductioners[reductioner_index];
      do{
        var first_denominator = Math.round((Math.floor(Math.random()*9)+1)*first_reductioner);
      }while(first_denominator > 20);
      var first_numerator =  Math.floor(Math.random()*(first_denominator-1)+1);
      do{
        var second_numerator = Math.round((Math.floor(Math.random()*9)+1)*first_reductioner);
      }while(second_numerator > 20);
      var second_denominator = second_numerator + Math.floor(Math.random()*10) + 1;
      var result_denominator = Math.round(first_denominator * second_denominator);
      var result_numerator = Math.round(first_numerator * second_numerator);
      // 分数可视化
      transfer_fraction_result(0, result_numerator, result_denominator);
      first_number = "f" + "0" + "," + first_numerator.toString() + "," + first_denominator.toString();
      second_number = "f" + "0" + "," + second_numerator.toString() + "," + second_denominator.toString();
      var multiplier_order = Math.floor(Math.random()*2);
      if(multiplier_order == 0){
        horizontal_type = [first_number, "×", second_number, "="];
        //horizontal_type = [first_number, "×", second_number, "=", result];
      }else{
        horizontal_type = [second_number, "×", first_number, "="];
        //horizontal_type = [second_number, "×", first_number, "=", result];
      };
    }while(horizontal_type == pre_horizontal_type);
    // 转换分数格式，方便用户输入
    transfer_result_fraction_for_input();
    // 计算cavas的长度，获取字体高度，生成绘图区
    ht_length_cal();
    var font_size = $(".par").css("font-size");
    font_size = font_size.replace("px", "");
    var canvas_height = font_size*2;
    var canvas_width = Math.ceil(ht_length*canvas_height/3);
    var canvas_html = "<canvas id=\"canvas_25\" width=\"" + canvas_width + "\" height=\"" + canvas_height + "\" style=\"vertical-align: middle;\"> 您的浏览器不支持 HTML5 canvas 标签。</canvas>" 
    $("#par_unit_25").html(canvas_html);
    // 输出横式
    draw_fraction("#canvas_25");
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 简便运算
  $("#btn_fraction_multiple_shortcut").click(function(){
    do{
        var multiple_times = [10, 100];
        var multiple_times_index = Math.floor(Math.random()*multiple_times.length);
        var multiple_time = multiple_times[multiple_times_index];
    var question_type = Math.floor(Math.random()*6);
    switch (question_type)
    {
    case 0:                    // 两数相乘的简便计算（假分数）
      var first_integer = Math.floor(Math.random()*10)+11;   //范围11-20
      var first_denominator = Math.floor(Math.random()*9)+2;  //范围2-10
      var first_numerator = Math.floor(Math.random()*(first_denominator-1))+1;
      first_number = "f" + first_integer.toString() + "," + first_numerator.toString() + "," + first_denominator.toString();
      second_number = first_denominator;
      result = Math.round(first_integer * second_number) + first_numerator;
      var choose = Math.floor(Math.random()*2)+1;
      switch(choose)
      {
      case 1:
        horizontal_type = [first_number, "×", second_number, "="];
        // horizontal_type = [first_number, "×", second_number, "=", result];
      break;
      case 2:
        horizontal_type = [second_number, "×", first_number, "="];
        // horizontal_type = [second_number, "×", first_number, "=", result];
      break;
      };
    break;
    case 1:                    // 两数相乘的简便计算（真分数）
      var first_denominator = Math.floor(Math.random()*88)+12;  //范围12-100
      var first_numerator = Math.floor(Math.random()*first_denominator)+1;
      first_number = "f" + "0" + "," + first_numerator.toString() + "," + first_denominator.toString();
      var add_or_subtract = Math.floor(Math.random()*2);
      switch(add_or_subtract)
      {
      case 1:
        second_number = first_denominator + 1;
	result_integer = first_numerator;
        result_numerator =  first_numerator;
	result_denominator = first_denominator;
      break;
      case 0:
        second_number = first_denominator - 1;
	result_integer = first_numerator-1;
        result_numerator =  first_denominator - first_numerator;
	result_denominator = first_denominator;
      break;
      };
      // 分数可视化
      transfer_fraction_result(result_integer, result_numerator, result_denominator);
      var choose = Math.floor(Math.random()*2)+1;
      switch(choose)
      {
      case 1:
        horizontal_type = [first_number, "×", second_number, "="];
        // horizontal_type = [first_number, "×", second_number, "=", result];
      break;
      case 2:
        horizontal_type = [second_number, "×", first_number, "="];
        // horizontal_type = [second_number, "×", first_number, "=", result];
      break;
      };
    break;
    case 2:                // 三个数相乘的简便计算
      var first_denominator = Math.floor(Math.random()*18)+2;
      var first_numerator =  Math.floor(Math.random()*(first_denominator-1))+1;
      do{
        var second_denominator = Math.floor(Math.random()*18)+2;
      }while(second_denominator == first_denominator);
      var second_numerator =  Math.floor(Math.random()*(second_denominator-1))+1;
      third_numerator = first_denominator * (Math.floor(Math.random()*5)+1);
      third_denominator = Math.round(first_numerator * second_numerator);
      if(third_denominator > third_numerator){
        third_number = "f" + "0" + "," + third_numerator.toString() + "," + third_denominator.toString();
        var result_denominator = second_denominator;
        var result_numerator = Math.round(third_numerator/first_denominator);
      }else{
        third_number = first_denominator * (Math.floor(Math.random()*5)+1);
        var result_denominator = second_denominator;
        var result_numerator = Math.round(first_numerator * second_numerator * third_number/first_denominator);
      };
      // 分数可视化
      transfer_fraction_result(0, result_numerator, result_denominator);
      first_number = "f" + "0" + "," + first_numerator.toString() + "," + first_denominator.toString();
      second_number = "f" + "0" + "," + second_numerator.toString() + "," + second_denominator.toString();
      var choose = Math.floor(Math.random()*4);
      switch(choose)
      {
      case 0:
         horizontal_type = [third_number, "×", second_number, "×", first_number, "="];
         // horizontal_type = [third_number, "×", second_number, "×", first_number, "=", result];
      break;
      case 1:
         horizontal_type = [first_number, "×", second_number, "×", third_number, "="];
         // horizontal_type = [first_number, "×", second_number, "×", third_number, "=", result];
      break;
      case 2:
         horizontal_type = [second_number, "×", first_number, "×", third_number, "="];
         // horizontal_type = [second_number, "×", first_number, "×", third_number, "=", result];
      break;
      case 3:
         horizontal_type = [second_number, "×", third_number, "×", first_number, "="];
         // horizontal_type = [second_number, "×", third_number, "×", first_number, "=", result];
      break;
      }
    break;
    case 3:               // 三个数乘加的简便计算
      var first_denominator = Math.floor(Math.random()*100)+2;
      var first_numerator = Math.floor(Math.random()*(first_denominator-1))+1;
      var second_denominator = first_denominator;
      var second_numerator = first_numerator;
      third_number = first_denominator - 1;
      result = first_numerator;
      // 分数可视化
      first_number = "f" + "0" + "," + first_numerator.toString() + "," + first_denominator.toString();
      second_number = "f" + "0" + "," + second_numerator.toString() + "," + second_denominator.toString();

      var choose = Math.floor(Math.random()*3)+1;
      switch(choose)
      {
      case 1:
         horizontal_type = [first_number, "×", third_number, "+", second_number, "="];
         // horizontal_type = [first_number, "×", third_number, "+", second_number, "=", result];
      break;
      case 2:
         horizontal_type = [first_number, "+", third_number, "×", second_number, "="];
         // horizontal_type = [first_number, "+", third_number, "×", second_number, "=", result];
      break;
      case 3:
         horizontal_type = [third_number, "×", first_number, "+", second_number, "="];
         // horizontal_type = [third_number, "×", first_number, "+", second_number, "=", result];
      break;
      case 4:
         horizontal_type = [ first_number, "+", second_number, "×", third_number, "="];
         // horizontal_type = [ first_number, "+", second_number, "×", third_number, "=", result];
      break;
      };
    break;
    case 4:               // 四个数乘加的简便计算
      var first_denominator = Math.floor(Math.random()*10)+2;
      var first_numerator = Math.floor(Math.random()*(first_denominator-1))+1;
      var second_denominator = first_denominator;
      var second_numerator = first_denominator-first_numerator;
      do{
      var third_denominator = Math.floor(Math.random()*10)+2;
      }while(third_denominator == first_denominator);
      var third_numerator = Math.floor(Math.random()*(third_denominator-1))+1;
      var result_numerator = third_numerator;
      var result_denominator = third_denominator;
      // 分数可视化
      transfer_fraction_result(0, result_numerator, result_denominator);
      first_number = "f" + "0" + "," + first_numerator.toString() + "," + first_denominator.toString();
      second_number = "f" + "0" + "," + second_numerator.toString() + "," + second_denominator.toString();
      third_number = "f" + "0" + "," + third_numerator.toString() + "," + third_denominator.toString();

      var choose = Math.floor(Math.random()*3)+1;
      switch(choose)
      {
      case 1:
         horizontal_type = [first_number, "×", third_number, "+", second_number, "×", third_number, "="];
         // horizontal_type = [first_number, "×", third_number, "+", second_number, "×", third_number, "=", result];
      break;
      case 2:
         horizontal_type = [first_number, "×", third_number, "+", third_number, "×", second_number, "="];
         // horizontal_type = [first_number, "×", third_number, "+", third_number, "×", second_number, "=", result];
      break;
      case 3:
         horizontal_type = [third_number, "×", first_number, "+", third_number, "×", second_number, "="];
         // horizontal_type = [third_number, "×", first_number, "+", third_number, "×", second_number, "=", result];
      break;
      case 4:
         horizontal_type = [third_number, "×", first_number, "+", second_number, "×", third_number, "="];
         // horizontal_type = [third_number, "×", first_number, "+", second_number, "×", third_number, "=", result];
      break;
      };
    case 5:               // 四个数乘减的简便计算
      var first_integer = Math.floor(Math.random()*10)+1;
      var first_denominator = Math.floor(Math.random()*10)+2;
      var first_numerator = Math.floor(Math.random()*(first_denominator-1))+1;
      do{
        var second_integer = Math.floor(Math.random()*10);
      }while(second_integer >= first_integer);
      var second_denominator = first_denominator;
      var second_numerator = first_numerator;
      do{
        var third_denominator = Math.floor(Math.random()*10)+2;
      }while(third_denominator == first_denominator);
      var third_numerator = Math.floor(Math.random()*(third_denominator-1))+1;
      var result_numerator = Math.round((first_integer-second_integer)*third_numerator);
      var result_denominator = third_denominator;
      // 分数可视化
      transfer_fraction_result(0, result_numerator, result_denominator);
      first_number = "f" + first_integer + "," + first_numerator.toString() + "," + first_denominator.toString();
      second_number = "f" + second_integer + "," + second_numerator.toString() + "," + second_denominator.toString();
      third_number = "f" + "0" + "," + third_numerator.toString() + "," + third_denominator.toString();

      var choose = Math.floor(Math.random()*3)+1;
      switch(choose)
      {
      case 1:
         horizontal_type = [first_number, "×", third_number, "-", second_number, "×", third_number, "="];
         // horizontal_type = [first_number, "×", third_number, "-", second_number, "×", third_number, "=", result];
      break;
      case 2:
         horizontal_type = [first_number, "×", third_number, "-", third_number, "×", second_number, "="];
         // horizontal_type = [first_number, "×", third_number, "-", third_number, "×", second_number, "=", result];
      break;
      case 3:
         horizontal_type = [third_number, "×", first_number, "-", third_number, "×", second_number, "="];
         // horizontal_type = [third_number, "×", first_number, "-", third_number, "×", second_number, "=", result];
      break;
      case 4:
         horizontal_type = [third_number, "×", first_number, "-", second_number, "×", third_number, "="];
         // horizontal_type = [third_number, "×", first_number, "-", second_number, "×", third_number, "=", result];
      break;
     }
    break;
    };
    }while(horizontal_type == pre_horizontal_type);
    // 转换分数格式，方便用户输入
    transfer_result_fraction_for_input();
    // 计算cavas的长度，获取字体高度，生成绘图区
    ht_length_cal();
    var font_size = $(".par").css("font-size");
    font_size = font_size.replace("px", "");
    var canvas_height = font_size*2;
    var canvas_width = Math.ceil(ht_length*canvas_height/3);
    var canvas_html = "<canvas id=\"canvas_25\" width=\"" + canvas_width + "\" height=\"" + canvas_height + "\" style=\"vertical-align: middle;\"> 您的浏览器不支持 HTML5 canvas 标签。</canvas>" 
    $("#par_unit_25").html(canvas_html);
    // 输出横式
    draw_fraction("#canvas_25");
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 二十六单元： 分数的除法
  // 分数除以整数
  $("#btn_fraction_divide_integer").click(function(){
    do{ 
      var reductioners = [2, 3, 5, 7, 11, 13, 17, 19];
      var reductioner_index = Math.floor(Math.random()*reductioners.length);
      var first_reductioner = reductioners[reductioner_index];
      do{
        var first_numerator = Math.round((Math.floor(Math.random()*9)+1)*first_reductioner);
      }while(first_numerator > 20);
      var first_denominator =  first_numerator + Math.floor(Math.random()*10);
      do{
        var second_number = Math.round((Math.floor(Math.random()*9)+1)*first_reductioner);
      }while(first_denominator == second_number);
      var result_denominator = Math.round(first_denominator * second_number);
      var result_numerator = first_numerator;
      // 分数可视化
      transfer_fraction_result(0, result_numerator, result_denominator);
      first_number = "f" + "0" + "," + first_numerator.toString() + "," + first_denominator.toString();
      var multiplier_order = Math.floor(Math.random()*2);
      horizontal_type = [first_number, "÷", second_number, "="];
      // horizontal_type = [first_number, "÷", second_number, "=", result];
    }while(horizontal_type == pre_horizontal_type);
    // 转换分数格式，方便用户输入
    transfer_result_fraction_for_input();
    // 计算cavas的长度，获取字体高度，生成绘图区
    ht_length_cal();
    var font_size = $(".par").css("font-size");
    font_size = font_size.replace("px", "");
    var canvas_height = font_size*2;
    var canvas_width = Math.ceil(ht_length*canvas_height/3);
    var canvas_html = "<canvas id=\"canvas_26\" width=\"" + canvas_width + "\" height=\"" + canvas_height + "\" style=\"vertical-align: middle;\"> 您的浏览器不支持 HTML5 canvas 标签。</canvas>" 
    $("#par_unit_26").html(canvas_html);
    // 输出横式
    draw_fraction("#canvas_26");
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });

  // 分数整数除以分数
  $("#btn_fraction_divide_fraction").click(function(){
    do{ 
      var reductioners = [2, 3, 5, 7, 11, 13, 17, 19];
      var reductioner_index = Math.floor(Math.random()*reductioners.length);
      var first_reductioner = reductioners[reductioner_index];

      first_number = 0;
      var first_numerator = 0;
      var first_denominator = 0;
      var integer_or_fraction = Math.floor(Math.random()*2);
      if(integer_or_fraction==0){
        first_numerator = Math.round((Math.floor(Math.random()*9)+1)*first_reductioner);
        first_denominator =  1;
        first_number = first_numerator;
      }else{
      do{
        first_numerator = Math.round((Math.floor(Math.random()*9)+1)*first_reductioner);
        first_denominator =  Math.floor(Math.random()*20)+1+first_numerator;
        first_number = "f" + "0" + "," + first_numerator.toString() + "," + first_denominator.toString();
      }while(first_numerator > 20);
      };

      do{
        var second_numerator = Math.round((Math.floor(Math.random()*9)+1)*first_reductioner);
      }while(second_numerator > 20);
      var second_denominator =  Math.floor(Math.random()*20)+1+second_numerator;

      var result_numerator = Math.round(first_numerator * second_denominator);
      var result_denominator = Math.round(first_denominator * second_numerator);
      // 分数可视化
      transfer_fraction_result(0, result_numerator, result_denominator);
      second_number = "f" + "0" + "," + second_numerator.toString() + "," + second_denominator.toString();
        horizontal_type = [first_number, "÷", second_number, "="];
        //horizontal_type = [first_number, "÷", second_number, "=", result];
    }while(horizontal_type == pre_horizontal_type);
    // 转换分数格式，方便用户输入
    transfer_result_fraction_for_input();
    // 计算cavas的长度，获取字体高度，生成绘图区
    ht_length_cal();
    var font_size = $(".par").css("font-size");
    font_size = font_size.replace("px", "");
    var canvas_height = font_size*2;
    var canvas_width = Math.ceil(ht_length*canvas_height/3);
    var canvas_html = "<canvas id=\"canvas_26\" width=\"" + canvas_width + "\" height=\"" + canvas_height + "\" style=\"vertical-align: middle;\"> 您的浏览器不支持 HTML5 canvas 标签。</canvas>" 
    $("#par_unit_26").html(canvas_html);
    // 输出横式
    draw_fraction("#canvas_26");
    pre_horizontal_type = horizontal_type;
    last_btn = "#" + $(this).attr("id");
    $(".input_class").focus();
  });
  // 分数混合运算
  // btn_fraction_divide_shortcut

  // 下面是一些功能
  // 转换分数结果以便输出
  function transfer_result_fraction_for_input(){
    if(result[0] == "f"){
      new_number_string = result.substr(1);
      var new_result = new_number_string.split(",");
      if(new_result[0] == 0){
        result = new_result[1] + "/" + new_result[2];
      }else{
        result = new_result[0] + "+" + new_result[1] + "/" + new_result[2]
      };
    };
  };
  // 计算html5绘图输出的长度
function ht_length_cal(){
  ht_length = 0;
  for(var i=0; i < horizontal_type.length; i++){
    var number_part = horizontal_type[i];
    var entry_flag = number_part[0];
    if(entry_flag == "f"){
      number_part = number_part.split(",");
      var integer_part = number_part[0];
      var numerator_part = number_part[1];
      var denominator_part = number_part[2];
      var fraction_length = 0;
      var integer_length = 0;
      if(integer_part == "f0"){
        integer_length = 0;
      }else{
        integer_length = integer_part.length-1;
      };
      if (numerator_part.length > denominator_part.length){
        fraction_length = numerator_part.toString().length
      }else{
        fraction_length = denominator_part.toString().length
      };
      ht_length = ht_length + integer_length + fraction_length;
    }else{
      ht_length = ht_length + number_part.toString().length;
    }
  };
};

// html5绘图完成分式的输出
function draw_fraction(canvas_id){
  var c = $(canvas_id)[0];
  var ctx=c.getContext("2d");
  var w = c.width;    // 画布的宽
  var h = c.height;   // 画布的高
  var start_x = 0;    // 画笔的水平起点
  ctx.font = h/2 + "px arial";
  // 输出横式的各项
  for( var entry = 0; entry < horizontal_type.length; entry++){
    var number_part = horizontal_type[entry].toString();
    var entry_flag = number_part[0];
    switch (entry_flag)
    {
    case "f":       // 处理分数
      number_part = number_part.substr(1);
      number_part = number_part.split(",");
      var integer_part = number_part[0] || 0;   // 整数部分
      var numerator_part = number_part[1];      // 分子部分
      var denominator_part = number_part[2];    // 分母部分
      // 调整分子或分母的位置
      var fraction_length = 0;          // 分数部分的长度
      var numerator_offset = 0;        // 分子水平位置偏移量
      var denominator_offset = 0;     // 分母水平位置偏移量
      if (numerator_part.length > denominator_part.length){
        fraction_length = numerator_part.length;
        denominator_offset = (numerator_part.length - denominator_part.length)/2;
      }else{
        fraction_length = denominator_part.length;
        numerator_offset = (denominator_part.length - numerator_part.length)/2;
      };
      // 开始输出分数
      if (integer_part == 0 ){
      }else{
        // 整数部分
        var integer_h = h*2/3;
        ctx.fillText(integer_part,start_x, integer_h);
        start_x = start_x + h*9/30*integer_part.length ; 
      };
      // 分子部分
      var numerator_x = start_x + numerator_offset*h*9/30;
      var numerator_y = h/12*5;
      ctx.fillText(numerator_part,numerator_x, numerator_y); 
      // 分数线部分
      ctx.lineWidth = h/30;
      ctx.moveTo( start_x, h/2);
      ctx.lineTo(start_x + h*8/30*fraction_length,h/2);
      ctx.stroke();
      // 分母部分
      var denominator_x = start_x + denominator_offset*h*9/30;
      var denominator_y = h/12*11;
      ctx.fillText(denominator_part,denominator_x,denominator_y);
      // 向右移动绘画的起点
      start_x = start_x + h/3*fraction_length;
    break;
    default:          // 处理分数之外的其他字符
      var integer_h = h*2/3;
      ctx.fillText(number_part, start_x, integer_h);
      start_x = start_x + h/3*number_part.length ; 
    break;
    };
    ctx.save();
  };
};

  // 转换分数格式
  function transfer_fraction_result(result_integer, result_numerator, result_denominator){
    result_numerator = result_denominator * result_integer + result_numerator;
    // 简化分数
    function simplify_fraction(){
      var prime_number = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97];
      for(var i=0; i<prime_number.length; i++){
        if(result_numerator%prime_number[i] == 0 && result_denominator % prime_number[i] == 0){
          result_numerator = result_numerator / prime_number[i];
	  result_denominator = result_denominator / prime_number[i];
	  simplify_fraction();
        };
      };
    }
      if(result_numerator%result_denominator == 0){
        result = Math.floor(result_numerator/result_denominator);
        return result;
      }else if(result_numerator > result_denominator){
        result_integer = Math.floor(result_numerator/result_denominator);
	result_numerator = result_numerator%result_denominator;
        simplify_fraction();
        result = "f" + result_integer.toString() + "," + result_numerator.toString() + "," + result_denominator.toString();
	return result;
      }else{
        simplify_fraction();
        result = "f" + "0" + "," + result_numerator.toString() + "," + result_denominator.toString();
	return result;
      }
  };
  // 监听输入框的输入
    $(".input_class").keypress(function(event){
      var keycode = event.which;
      if(keycode == 13){check_answer();};
    });

  // 展示错题按钮
  $("#btn_show_fail").click(function(){
    var fail_hy = "";
    if (horizontal_type_fail.length==0){
      fail_hy = "没有做错的题哦！";
    }else{
      var fail_hy = horizontal_type_fail.join("  ");
    };
    $("#par_fail").html(function(){
      return fail_hy; 
    });
  });

  // 错题本
  $("#btn_test_fail").click(function(){
    // 检查chars是否有元素
    var chars=horizontal_type_fail;
    if (chars.length == 0){
      alert("恭喜恭喜！大家恭喜！没有错题啦！");
      // $(this).css("color", "blue").html("已过关");
      $(".par").html(function(){ return ""; });
    } else{
      //随机选择一个元素进行测试
      var id = Math.floor(Math.random()*chars.length);
      result = result_fail[id].toString();
      horizontal_type = chars[id];
      // 转换分数格式，方便用户输入
      // transfer_result_fraction_for_input();
      // 计算cavas的长度，获取字体高度，生成绘图区
      ht_length_cal();
      var font_size = $(".par").css("font-size");
      font_size = font_size.replace("px", "");
      var canvas_height = font_size*2;
      var canvas_width = Math.ceil(ht_length*canvas_height/3);
      var canvas_html = "<canvas id=\"canvas_fail\" width=\"" + canvas_width + "\" height=\"" + canvas_height + "\" style=\"vertical-align: middle;\"> 您的浏览器不支持 HTML5 canvas 标签。</canvas>" 
      $("#par_fail").html(canvas_html);
      // 输出横式
      draw_fraction("#canvas_fail");
      pre_horizontal_type = horizontal_type;
      last_btn = "#" + $(this).attr("id");
      $(".input_class").focus();
    }
  });
  // 设置训练强度
  $(".settings").click(function(){
    maxtime=prompt("计时时间\n单位：分钟", "1");
    alert("点击确认则开始计时，所有分数都被清零？");
    score = 0;
    $(".right-top-count").html(function(){return score});
    timer = setTimeout(function(){
      var msg = "时间到！\n您本次计时的得分是" + score + "！\n加油！";
      alert(msg);
    },maxtime*60*1000);
  });

//下面是抽查测试部分
  var zi_part_test = [];
  var point_part_test = {};
  var part_test_times = 0;
  $("#begin_org").click(function(){
    // 初始化测试
    var select_unit = [].concat($("#select_unit").val());
    // alert(select_unit);
    if (select_unit.toString() == "") {alert("请先选择合适的单元。"); return false;} 
    if (zi_part_test.length == 0){
      var zi_part_test_step=0;
      for (var i=0; i < select_unit.length; i++){
        var single_unit = select_unit[i];
        var trans_single_unit = eval(single_unit);
        for (var j=0; j < trans_single_unit.length; j++){
          zi_part_test[zi_part_test_step]=trans_single_unit[j];
          zi_part_test_step++;
        }
      }
      // alert(zi_part_test);
      // 初始化项目次数
      for(var s=0; s<zi_part_test.length; s++){point_part_test[zi_part_test[s]]=0;};
      //分数清零。
      score = 0; $(".right-top-count").html(function(){return score});
      alert("测试开始，分数清零");
    };
    // 获取试题数目
    var part_test_entry_num = $("#part_test_entry_num").val();
    // 开始测试
    if (part_test_times < part_test_entry_num){
      practice(zi_part_test,point_part_test,"par_part_test");
      ++part_test_times;
    }else{
      //结束测试
      $("#par_part_test").html(""); 
      var part_test_score = Math.round(score*(100/part_test_entry_num));
      var part_test_message = "本次测试" + part_test_score + "分！"; 
      alert(part_test_message);
      zi_part_test = [];
      part_test_times = 0;
      $("#select_unit").val(null);
    };
  });
});
  //翻页时清除par区的内容
  function clear_par(){ $(".par").text(""); };
</script>
</head>

<body onhashchange="clear_par()">

<div data-role="page" id="home">
  <div data-role="header">
    <h1>小学计算大挑战·首页</h1>
  </div>
  <div data-role="content">
    <div style="text-align: center;">
      <p>欢迎使用！</p>
      <p>注意，本应用配套的教材是：人民教育出版社小学数学课本</p>
      <a href="#index" data-role="button" data-transition="pop" style="width: 33%; margin: auto;background-color: rgb(140,191,0);">点击这里，开始练习</a>
    </div>
    <div data-role="collapsible" data-collapsed="false">
      <h4>······使用提示······</h4>
      <p>祝你好运啦！</p>
    </div>
    <div data-role="collapsible">
      <h4>······怎么版面乱七八糟的？······</h4>
      <p>很有可能是浏览器禁用了JavaScript，您需要手动开启JavaScript。</p>
    </div>
    <div data-role="collapsible" >
      <h4>······已知bug······</h4>
      <ol>
        <li>抽查检测部分，测验完成之后仍然会弹出“不要气馁”的窗口，右上角的计分会自动减少一分——这是因为practice函数在运行。</li>
        <li>功能改进：如果无需数据持久化，欢迎提出意见！</li>
      </ol>
    </div>
    <div data-role="collapsible">
      <h4>······许可证······</h4>
      <p>GPLv3。内容详见<a href="http://www.gnu.org/licenses/gpl-3.0.html">这里</a>。</p>
    </div>
    <div data-role="collapsible" style="text-align: center;">
      <h4>······作者······</h4>
      <p>我是李启训（kinder.ga@outlook.com）<br>一起参加<a href="http://www.gnu.org/home.zh-cn.html">自由软件运动</a>吧！</p>
    </div>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="index">
  <div data-role="header">
    <h1>目录</h1>
    <div data-role="navbar"> <ul>
        <li><a href="#home" data-icon="arrow-l">上一页</a></li>
        <li><a href="#unit_0" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div> <!-- navbar -->
  </div>
  <div data-role="content" style="text-align: center;">
    <h3>请选择适当的单元：</h3>
    <ul data-role="listview">
      <li data-role="list-divider">一年级上册</li>
      <li> <a href="#unit_0" data-transition="pop">10以内各数的认识</a></li>
      <li> <a href="#unit_1" data-transition="pop">10以内的加减运算</a></li>
      <li> <a href="#unit_2" data-transition="pop">11~20各数的认识</a></li>
      <li> <a href="#unit_3" data-transition="pop">20以内的进位加法</a></li>
      <li data-role="list-divider">一年级下册</li>
      <li> <a href="#unit_4" data-transition="pop">20以内的退位减法</a></li>
      <li> <a href="#unit_5" data-transition="pop">100以内数的加减法（一）</a></li>
      <li data-role="list-divider">二年级上册</li>
      <li> <a href="#unit_6" data-transition="pop">100以内数的加减法（二）</a></li>
      <li> <a href="#unit_7" data-transition="pop">表内乘法</a></li>
      <li data-role="list-divider">二年级下册</li>
      <li> <a href="#unit_8" data-transition="pop">表内除法</a></li>
      <li> <a href="#unit_9" data-transition="pop">万以内数的加减法（一）</a></li>
      <li data-role="list-divider">三年级上册</li>
      <li> <a href="#unit_10" data-transition="pop">万以内数的加减法（二）</a></li>
      <li> <a href="#unit_11" data-transition="pop">有余数的除法</a></li>
      <li> <a href="#unit_12" data-transition="pop">多位数乘一位数</a></li>
      <li> <a href="#unit_13" data-transition="pop">分数的简单计算</a></li>
      <li data-role="list-divider">三年级下册</li>
      <li> <a href="#unit_14" data-transition="pop">除数是一位数的除法</a></li>
      <li> <a href="#unit_15" data-transition="pop">两位数乘两位数</a></li>
      <li> <a href="#unit_16" data-transition="pop">小数的简单计算</a></li>
      <li data-role="list-divider">四年级上册</li>
      <li> <a href="#unit_17" data-transition="pop">三位数乘两位数</a></li>
      <li> <a href="#unit_18" data-transition="pop">除数是两位数的除法</a></li>
      <li data-role="list-divider">四年级下册</li>
      <li> <a href="#unit_19" data-transition="pop">四则运算</a></li>
      <li> <a href="#unit_20_1" data-transition="pop">加法运算定律</a></li>
      <li> <a href="#unit_20_2" data-transition="pop">乘法运算定律</a></li>
      <li> <a href="#unit_20_3" data-transition="pop">运算定律与简便计算</a></li>
      <li> <a href="#unit_21" data-transition="pop">小数的加法和减法</a></li>
      <li data-role="list-divider">五年级上册</li>
      <li> <a href="#unit_22" data-transition="pop">小数乘法</a></li>
      <li> <a href="#unit_23" data-transition="pop">小数除法</a></li>
      <li data-role="list-divider">五年级下册</li>
      <li> <a href="#unit_24" data-transition="pop">分数的加减法（一）</a></li>
      <li> <a href="#unit_24_2" data-transition="pop">分数的加减法（二）</a></li>
      <li data-role="list-divider">六年级上册</li>
      <li> <a href="#unit_25" data-transition="pop">分数的乘法</a></li>
      <li> <a href="#unit_26" data-transition="pop">分数的除法</a></li>
      <li> <a href="#fail" data-transition="pop">错题本</a></li>
    </ul>
  </div>
</div>

<div data-role="page" id="unit_0">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>1～10各数的认识</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="#index" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_1" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <div data-role=fieldcontain>
      <label for="addend">加数的限制:</label>
      <select name="addend" id="addend" data-role="slider">
      <option value="on">包含</option>
      <option value="off" selected>限制</option>
      </select>
    </div>
    <div data-role=fieldcontain>
      <label>加数的范围</label>
      <input id="set_top_number_unit_0" type="range" max="9" min="1" step="1" value="10"/>
    </div>
    <div class="ui-grid-a">
      <div class="ui-block-a">
        <button id="btn_10_meet_add" data-inline="true" style="width: 100%;">10以内各个数的加法</button>
      </div>
      <div class="ui-block-b">
        <button id="btn_10_meet_subtract" data-inline="true" style="width: 100%;">10以内各个数的减法</button>
      </div>
    </div>
    <div class="par" style="text-align: center; margin: 0px;"></div>
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="unit_1">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>10以内的加减运算</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="##unit_0" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_2" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <div class="ui-grid-d">
      <div class="ui-block-a">
        <button id="10_add" data-inline="true" style="width: 100%;">1. 10以内两个数相加</button>
      </div>
      <div class="ui-block-b">
        <button id="10_substract" data-inline="true" style="width: 100%;">2. 10以内两个数相减</button>
      </div>
      <div class="ui-block-c">
        <button id="10_serial_add" data-inline="true" style="width: 100%;">3. 10以内三个数连加</button>
      </div>
      <div class="ui-block-d">
        <button id="10_serial_substract" data-inline="true" style="width: 100%;">4. 10以内三个数连减</button>
      </div>
      <div class="ui-block-e">
        <button id="10_serial_add_and_substract" data-inline="true" style="width: 100%;">5. 10以内三个数加减混合运算</button>
      </div>
    </div><!-- ui-grid-d -->
    <div class="par" style="text-align: center; margin: 0px;"></div>
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="unit_2">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>11~20各数的认识</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="#unit_1" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_3" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <div class="ui-grid-d">
      <div class="ui-block-a">
        <button id="btn_20_not_carry_add" data-inline="true" style="width: 100%;">20以内的非进位加法</button>
      </div>
      <div class="ui-block-b">
        <button id="btn_20_not_abdication_substract" data-inline="true" style="width: 100%;">20以内的非进位减法</button>
      </div>
      <div class="ui-block-c">
        <button id="btn_20_not_carry_serial_add" data-inline="true" style="width: 100%;">20以内三个数不进位连加</button>
      </div>
      <div class="ui-block-d">
        <button id="btn_20_not_abdication_serial_substract" data-inline="true" style="width: 100%;">20以内三个数不退位连减</button>
      </div>
      <div class="ui-block-e">
        <button id="btn20_not_c_and_ab_serial_add_and_substract" data-inline="true" style="width: 100%;">20以内三个数不进退位混合加减运算</button>
      </div>
    </div><!-- ui-grid-d -->
    <div class="par" style="text-align: center; margin: 0px;"></div>
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="unit_3">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>20以内的进位加法</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="#unit_2" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_4" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <div class="ui-grid-b">
      <div class="ui-block-a">
        <button id="btn_20_carry_add" data-inline="true" style="width: 100%;">20以内的进位加法</button>
      </div>
      <div class="ui-block-b">
        <button id="btn_20_carry_serial_add" data-inline="true" style="width: 100%;">20以内的进位连加法</button>
      </div>
      <div class="ui-block-c">
        <button id="btn_20_serial_carry_add_and_substract" data-inline="true" style="width: 100%;">20以内的进位加减混合运算</button>
      </div>
    </div><!-- ui-grid-b -->
    <div class="par" style="text-align: center; margin: 0px;"></div>
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="unit_4">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>20以内退位减法</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="#unit_3" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_5" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <div class="ui-grid-b">
      <div class="ui-block-a">
        <button id="btn_20_abdication_substract" data-inline="true" style="width: 100%;">十几减几的退位运算</button>
      </div>
      <div class="ui-block-b">
        <button id="btn_20_abdication_serial_substract" data-inline="true" style="width: 100%;">十几减几的三位数退位连减运算</button>
      </div>
      <div class="ui-block-c">
        <button id="btn20_c_and_ab_serial_add_and_substract" data-inline="true" style="width: 100%;">十几减几的三位数进退位加减混合运算</button>
      </div>
    </div><!-- ui-grid-b -->
    <div class="par" style="text-align: center; margin: 0px;"></div>
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="unit_5">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>100以内数的加减法（一）</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="#unit_4" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_6" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <div class="ui-grid-d">
      <div class="ui-block-a">
        <button id="100_round_add_and_abstract_round" data-inline="true" style="width: 100%;">整十数加减整十数</button>
      </div>
      <div class="ui-block-b">
        <button id="100_2_digit_add_1d" data-inline="true" style="width: 100%;">两位数加一位数</button>
      </div>
      <div class="ui-block-c">
        <button id="100_2_digit_add_round" data-inline="true" style="width: 100%;">两位数加整十数</button>
      </div>
      <div class="ui-block-d">
        <button id="100_2_digit_subtract_1d" data-inline="true" style="width: 100%;">两位数减一位数</button>
      </div>
      <div class="ui-block-e">
        <button id="100_2_digit_subtract_round" data-inline="true" style="width: 100%;">两位数减整十数</button>
      </div>
    </div><!-- ui-grid-d -->
    <div class="par" style="text-align: center; margin: 0px;"></div>
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="unit_6">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>100以内数的加减法（二）</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="#unit_5" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_7" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <div class="ui-grid-d">
      <div class="ui-block-a">
        <button id="btn_100_2_digit_add_2d" data-inline="true" style="width: 100%;">两位数加两位数</button>
      </div>
      <div class="ui-block-b">
        <button id="btn_100_2_digit_subtract_2d" data-inline="true" style="width: 100%;">两位数减两位数</button>
      </div>
      <div class="ui-block-c">
        <button id="btn_100_serial_add" data-inline="true" style="width: 100%;">两位数的连加</button>
      </div>
      <div class="ui-block-d">
        <button id="btn_100_serial_subtract" data-inline="true" style="width: 100%;">两位数连减</button>
      </div>
      <div class="ui-block-e">
        <button id="btn_100_serial_add_and_substract" data-inline="true" style="width: 100%;">两位数加减混合</button>
      </div>
    </div><!-- ui-grid-d -->
    <div class="par" style="text-align: center; margin: 0px;"></div>
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="unit_7">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>表内乘法</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="#unit_6" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_8" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <div data-role=fieldcontain>
      <label for="factor">因数的限制:</label>
      <select name="factor" id="factor" data-role="slider">
      <option value="on" selected>包含</option>
      <option value="off">限制</option>
      </select>
    </div>
    <div data-role=fieldcontain>
      <label>因数的范围</label>
      <input id="set_top_number" type="range" max="9" min="1" step="1" value="9"/>
    </div>
    <div class="ui-grid-a">
      <div class="ui-block-a">
        <button id="btn_9_mutiple" data-inline="true" style="width: 100%;">表内乘法</button>
      </div>
      <div class="ui-block-b">
        <button id="btn_100_serial_multiple_add_and_substract" data-inline="true" style="width: 100%;">表内乘法和加减混合运算</button>
      </div>
    </div><!-- ui-grid-a -->
    <div class="par" style="text-align: center; margin: 0px;"></div>
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="unit_8">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>表内除法</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="#unit_7" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_9" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <div class="ui-grid-c">
      <div class="ui-block-a">
        <button id="btn_6_divide" data-inline="true" style="width: 100%;">表内除法（一）2～6</button>
      </div>
      <div class="ui-block-b">
        <button id="btn_9_divide" data-inline="true" style="width: 100%;">表内除法（二）7～9</button>
      </div>
      <div class="ui-block-c">
        <button id="btn_9_divide_all" data-inline="true" style="width: 100%;">表内除法（总）</button>
      </div>
      <div class="ui-block-d">
        <button id="btn_9_divide_serial" data-inline="true" style="width: 100%;">表内除法混合运算</button>
      </div>
    </div><!-- ui-grid-c -->
    <div class="par" style="text-align: center; margin: 0px;"></div>
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="unit_9">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>万以内数的加减法（一）</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="#unit_8" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_10" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <div class="ui-grid-a">
      <div class="ui-block-a">
        <button id="btn_hunds_thous_add_and_subtract" data-inline="true" style="width: 100%;">整百整千数的加减法</button>
      </div>
      <div class="ui-block-b">
        <button id="btn_hunds_tens_add_and_subtract" data-inline="true" style="width: 100%;">几百几十加减几百几十</button>
      </div>
    </div><!-- ui-grid-a -->
    <div class="par" style="text-align: center; margin: 0px;"></div>
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="unit_10">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>万以内数的加减法（二）</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="#unit_9" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_11" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <div class="ui-grid-c">
      <div class="ui-block-a">
        <button id="btn_1000_add" data-inline="true" style="width: 100%;">一千以内的加法</button>
      </div>
      <div class="ui-block-b">
        <button id="btn_10000_add" data-inline="true" style="width: 100%;">一万以内的加法</button>
      </div>
      <div class="ui-block-c">
        <button id="btn_1000_subtract" data-inline="true" style="width: 100%;">一千以内的减法</button>
      </div>
      <div class="ui-block-d">
        <button id="btn_10000_subtract" data-inline="true" style="width: 100%;">一万以内的减法</button>
      </div>
    </div><!-- ui-grid-c -->
    <div class="par" style="text-align: center; margin: 0px;"></div>
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="unit_11">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>有余数的除法</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="#unit_10" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_12" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <button id="btn_divide_have_remainder" data-inline="true" style="width: 100%;">有余数的除法</button>
    <div class="par" style="text-align: center; margin: 0px;"></div>
    <label>注意，结果出现余数时，省略号（……）用六个点（......）表示，比如商5余2， 写作“5......2”。
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="unit_12">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>多位数乘以一位数</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="#unit_11" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_13" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <div class="ui-grid-a">
      <div class="ui-block-a">
        <button id="btn_round_many_digit_mutiple_1d" data-inline="true" style="width: 100%;">口算乘法</button>
      </div>
      <div class="ui-block-b">
        <button id="btn_many_digit_mutiple_1d" data-inline="true" style="width: 100%;">多位数乘以一位数</button>
      </div>
    </div><!-- ui-grid-b -->
    <div class="par" style="text-align: center; margin: 0px;"></div>
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="unit_13">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>分数的简单计算</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="#unit_12" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_14" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <button id="btn_simple_fraction_add_and_subtract" data-inline="true" style="width: 100%;">分数的简单计算</button>
    <div id="par_unit_13" class="par" style="text-align: center; margin: 0px;"></div>
    <label>注意，分号（……）用正斜杠（/）表示，比如五分之二， 写作“2/5”。
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="unit_14">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>除数是一位数的除法</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="#unit_13" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_15" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <div class="ui-grid-b">
      <div class="ui-block-a">
        <button id="btn_round_many_digits_divide_1d" data-inline="true" style="width: 100%;">口算除法</button>
      </div>
      <div class="ui-block-b">
        <button id="btn_many_digits_with_0_divide_1d" data-inline="true" style="width: 100%;">商中间、末尾有0的除法</button>
      </div>
      <div class="ui-block-c">
        <button id="btn_many_digits_divide_1d" data-inline="true" style="width: 100%;">除数是一位数的除法</button>
      </div>
    </div><!-- ui-grid-c -->
    <div class="par" style="text-align: center; margin: 0px;"></div>
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="unit_15">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>两位数乘两位数</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="#unit_14" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_16" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <div class="ui-grid-c">
      <div class="ui-block-a">
        <button id="btn_round_tens_mutiple_round_tens" data-inline="true" style="width: 100%;">口算整十相乘</button>
      </div>
      <div class="ui-block-b">
        <button id="btn_2_digits_mutiple_round_tens" data-inline="true" style="width: 100%;">口算两位数乘整十数</button>
      </div>
      <div class="ui-block-c">
        <button id="btn_2_digits_mutiple_2_digits_not_carry" data-inline="true" style="width: 100%;">笔算不进位的两位数乘两位数</button>
      </div>
      <div class="ui-block-d">
        <button id="btn_2_digits_mutiple_2_digits" data-inline="true" style="width: 100%;">笔算两位数乘两位数</button>
      </div>
    </div><!-- ui-grid-c -->
    <div class="par" style="text-align: center; margin: 0px;"></div>
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="unit_16">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>简单的小数加减法</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="#unit_15" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_17" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <div class="ui-grid-a">
      <div class="ui-block-a">
        <button id="btn_simple_decimal_add" data-inline="true" style="width: 100%;">简单的小数加法</button>
      </div>
      <div class="ui-block-b">
        <button id="btn_simple_decimal_subtract" data-inline="true" style="width: 100%;">简单的小数减法</button>
      </div>
    </div><!-- ui-grid-a -->
    <div class="par" style="text-align: center; margin: 0px;"></div>
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="unit_17">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>三位数乘两位数</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="#unit_16" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_18" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <div class="ui-grid-a">
      <div class="ui-block-a">
        <button id="btn_3_digits_mutiple_round_tens" data-inline="true" style="width: 100%;">口算三位数乘整十数</button>
      </div>
      <div class="ui-block-b">
        <button id="btn_3_digits_mutiple_2_digits" data-inline="true" style="width: 100%;">三位数乘两位数</button>
      </div>
    </div><!-- ui-grid-b -->
    <div class="par" style="text-align: center; margin: 0px;"></div>
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="unit_18">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>除数是两位数的除法</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="#unit_17" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_19" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <div class="ui-grid-b">
      <div class="ui-block-a">
        <button id="btn_round_huns_tens_divide_round_tens" data-inline="true" style="width: 100%;">口算几百几十、几十除以整十</button>
      </div>
      <div class="ui-block-b">
        <button id="btn_3_digits_divide_2_digits" data-inline="true" style="width: 100%;">三位数整除两位数</button>
      </div>
      <div class="ui-block-c">
        <button id="btn_many_digits_divide_2_digits" data-inline="true" style="width: 100%;">多位数除以两位数</button>
      </div>
    </div><!-- ui-grid-c -->
    <div class="par" style="text-align: center; margin: 0px;"></div>
    <label>注意，结果出现余数时，省略号（……）用六个点（......）表示，比如商5余2， 写作“5......2”。
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="unit_19">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>四则运算</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="#unit_18" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_20_1" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <div class="ui-grid-b">
      <div class="ui-block-a">
        <button id="btn_mutiple_or_divide_and_plus_or_subtract" data-inline="true" style="width: 100%;">积商之和差混合</button>
      </div>
      <div class="ui-block-b">
        <button id="btn_2_mutiple_or_divide_and_plus_or_subtract" data-inline="true" style="width: 100%;">两个积商之和差混合</button>
      </div>
      <div class="ui-block-c">
        <button id="btn_3_step_with_brackets" data-inline="true" style="width: 100%;">含括号三步计算</button>
      </div>
    </div><!-- ui-grid-b -->
    <div class="par" style="text-align: center; margin: 0px;"></div>
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="unit_20_1">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>加法运算定律</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="#unit_19" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_20_2" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <div class="ui-grid-c">
      <div class="ui-block-a">
        <button id="btn_commutative_law_for_addtion" data-inline="true" style="width: 100%;">加法交换律</button>
      </div>
      <div class="ui-block-b">
        <button id="btn_associative_law_for_addition" data-inline="true" style="width: 100%;">加法结合律</button>
      </div>
      <div class="ui-block-c">
        <button id="btn_use_addition_laws_3_addend" data-inline="true" style="width: 100%;">应用（三个加数）</button>
      </div>
      <div class="ui-block-d">
        <button id="btn_use_addition_laws_4_addend" data-inline="true" style="width: 100%;">应用（四个加数）</button>
      </div>
    </div><!-- ui-grid-b -->
    <div class="par" style="text-align: center; margin: 0px;"></div>
    <label>注意，如果有两个空，则答题时两个数字之间用<b>空格</b>隔开。</label>
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="unit_20_2">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>乘法运算定律</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="#unit_20_1" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_20_3" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <div class="ui-grid-c">
      <div class="ui-block-a">
        <button id="btn_commutative_law_for_multiplication" data-inline="true" style="width: 100%;">乘法交换律</button>
      </div>
      <div class="ui-block-b">
        <button id="btn_associative_law_for_multiplication" data-inline="true" style="width: 100%;">乘法结合律</button>
      </div>
      <div class="ui-block-c">
        <button id="btn_distributive_law_for_multiplication" data-inline="true" style="width: 100%;">乘法分配律</button>
      </div>
      <div class="ui-block-d">
        <button id="btn_use_multiplication_laws" data-inline="true" style="width: 100%;">应用</button>
      </div>
    </div><!-- ui-grid-b -->
    <div class="par" style="text-align: center; margin: 0px;"></div>
    <label>注意，如果有两个空，则答题时两个数字之间用<b>空格</b>隔开。</label>
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="unit_20_3">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>简便运算</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="#unit_20_2" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_21" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <div class="ui-grid-d">
      <div class="ui-block-a">
        <button id="btn_shortcut_serial_subtractions" data-inline="true" style="width: 100%;">连减</button>
      </div>
      <div class="ui-block-b">
        <button id="btn_shortcut_addition_subtractions" data-inline="true" style="width: 100%;">加减</button>
      </div>
      <div class="ui-block-c">
        <button id="btn_shortcut_serial_division" data-inline="true" style="width: 100%;">连除</button>
      </div>
      <div class="ui-block-d">
        <button id="btn_shortcut_multiplication_division" data-inline="true" style="width: 100%;">乘除</button>
      </div>
      <div class="ui-block-e">
        <button id="btn_shortcut_multiplication_addition" data-inline="true" style="width: 100%;">乘加</button>
      </div>
    </div><!-- ui-grid-d -->
    <div class="par" style="text-align: center; margin: 0px;"></div>
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="unit_21">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>小数的加法和减法</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="#unit_20_3" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_22" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <div class="ui-grid-b">
      <div class="ui-block-a">
        <button id="btn_decimal_add_or_subtract" data-inline="true" style="width: 100%;">基础</button>
      </div>
      <div class="ui-block-b">
        <button id="btn_decimal_mixed_operation" data-inline="true" style="width: 100%;">混合</button>
      </div>
      <div class="ui-block-c">
        <button id="btn_decimal_add_and_subtract_shortcut" data-inline="true" style="width: 100%;">简便</button>
      </div>
    </div><!-- ui-grid-b -->
    <div class="par" style="text-align: center; margin: 0px;"></div>
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="unit_22">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>小数的乘法</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="#unit_21" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_23" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <div class="ui-grid-c">
      <div class="ui-block-a">
        <button id="btn_decimal_multiple_round_integer" data-inline="true" style="width: 100%;">乘十百千</button>
      </div>
      <div class="ui-block-b">
        <button id="btn_decimal_multiple_integer" data-inline="true" style="width: 100%;">乘整数</button>
      </div>
      <div class="ui-block-c">
        <button id="btn_decimal_multiple_basic" data-inline="true" style="width: 100%;">基本乘法</button>
      </div>
      <div class="ui-block-d">
        <button id="btn_decimal_multiple_shortcut" data-inline="true" style="width: 100%;">简便</button>
      </div>
    </div><!-- ui-grid-c -->
    <div class="par" style="text-align: center; margin: 0px;"></div>
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="unit_23">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>小数的除法</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="#unit_22" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_24" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <div class="ui-grid-d">
      <div class="ui-block-a">
        <button id="btn_decimal_divide_integer_1" data-inline="true" style="width: 100%;">整数够除</button>
      </div>
      <div class="ui-block-b">
        <button id="btn_decimal_divide_integer_0" data-inline="true" style="width: 100%;">整数商0</button>
      </div>
      <div class="ui-block-c">
        <button id="btn_decimal_divide_integer_tail" data-inline="true" style="width: 100%;">尾部添0</button>
      </div>
      <div class="ui-block-d">
        <button id="btn_decimal_divide_decimal" data-inline="true" style="width: 100%;">一个数除以小数</button>
      </div>
      <div class="ui-block-e">
        <button id="btn_decimal_divide_decimal_more" data-inline="true" style="width: 100%;">除数更多小数位</button>
      </div>
    </div><!-- ui-grid-d -->
    <div class="par" style="text-align: center; margin: 0px;"></div>
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="unit_24">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>分数的加法和减法（一）</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="#unit_23" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_24_2" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <div class="ui-grid-d">
      <div class="ui-block-a">
        <button id="btn_fraction_same_denominator_add" data-inline="true" style="width: 100%;">同分母加法</button>
      </div>
      <div class="ui-block-b">
	<button id="btn_fraction_same_denominator_subtract" data-inline="true" style="width: 100%;">同分母减法</button>
      </div>
      <div class="ui-block-c">
        <button id="btn_fraction_same_denominator_serial_add_subtract" data-inline="true" style="width: 100%;">同分母连加减</button>
      </div>
      <div class="ui-block-d">
        <button id="btn_fraction_diff_denominator_add" data-inline="true" style="width: 100%;">异分母加法</button>
      </div>
      <div class="ui-block-e">
        <button id="btn_fraction_diff_denominator_subtract" data-inline="true" style="width: 100%;">异分母减法</button>
      </div>
    </div><!-- ui-grid-d -->
    <div id="par_unit_24" class="par" style="text-align: center; margin: 0px;"></div>
    <label>注意，分数要用“整数+分子/分母"的方式表示。比如三又五分之二， 需要写作“3+2/5”；四分之三，需要写作"3/4"。
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="unit_24_2">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>分数的加法和减法（二）</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="#unit_24" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_25" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <div class="ui-grid-b">
      <div class="ui-block-a">
        <button id="btn_fraction_3_step" data-inline="true" style="width: 100%;">不带括号混合</button>
      </div>
      <div class="ui-block-b">
	<button id="btn_fraction_3_step_with_brackets" data-inline="true" style="width: 100%;">带括号混合</button>
      </div>
      <div class="ui-block-c">
        <button id="btn_fraction_add_subtract_shortcut" data-inline="true" style="width: 100%;">运算定律和简便运算</button>
      </div>
    </div><!-- ui-grid-b -->
    <div id="par_unit_24_2" class="par" style="text-align: center; margin: 0px;"></div>
    <label>注意，分数要用“整数+分子/分母"的方式表示。比如三又五分之二， 需要写作“3+2/5”；四分之三，需要写作"3/4"。
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="unit_25">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>分数的乘法（一）</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="#unit_24_2" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_26" data-icon="arrow-r">下一关</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <div class="ui-grid-b">
      <div class="ui-block-a">
        <button id="btn_fraction_multiple_integer" data-inline="true" style="width: 100%;">分数乘整数</button>
      </div>
      <div class="ui-block-b">
	<button id="btn_fraction_multiple_fraction" data-inline="true" style="width: 100%;">分数乘分数</button>
      </div>
      <div class="ui-block-c">
        <button id="btn_fraction_multiple_shortcut" data-inline="true" style="width: 100%;">简便运算</button>
      </div>
    </div><!-- ui-grid-b -->
    <div id="par_unit_25" class="par" style="text-align: center; margin: 0px;"></div>
    <label>注意，分数要用“整数+分子/分母"的方式表示。比如三又五分之二， 需要写作“3+2/5”；四分之三，需要写作"3/4"。
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="unit_26">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>分数的除法</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
        <li><a href="#unit_25" data-icon="arrow-l">上一关</a></li>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li><a href="#fail" data-icon="info">错题本</a></li>
        <li><a href="#unit_26" data-icon="arrow-r">毕业！</a></li>
      </ul>
    </div><!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <div class="ui-grid-a">
      <div class="ui-block-a">
        <button id="btn_fraction_divide_integer" data-inline="true" style="width: 100%;">分数除以整数</button>
      </div>
      <div class="ui-block-b">
	<button id="btn_fraction_divide_fraction" data-inline="true" style="width: 100%;">分数整数除以分数</button>
      </div>
    </div><!-- ui-grid-b -->
    <div id="par_unit_26" class="par" style="text-align: center; margin: 0px;"></div>
    <label>注意，分数要用“整数+分子/分母"的方式表示。比如三又五分之二， 需要写作“3+2/5”；四分之三，需要写作"3/4"。
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->

<div data-role="page" id="fail">
  <div data-role="header">
    <a href="#index" data-icon="home">目录</a>
    <h1>出错的字</h1>
    <button data-role="button"class="ui-btn-right"><span class="ui-li-count right-top-count" style="position: relative; right: 0em;"></span></button>
    <div data-role="navbar">
      <ul>
	<li><button class="settings" data-icon="gear">计时</button></li>
        <li> <a href="javascript:history.back(-1)" data-icon="back">返回</a></li>
      </ul>
    </div> <!-- navbar -->
  </div><!-- header -->
  <div data-role="content">
    <div class="ui-grid-a">
      <div class="ui-block-a">
        <button id="btn_show_fail" data-inline="true" style="width: 100%;">显示没有通过的横式</button>
      </div>
      <div class="ui-block-b">
        <button id="btn_test_fail" data-inline="true" style="width: 100%;">测试没有通过的横式</button>
      </div>
    </div><!-- ui-grid-a -->
    <div id="par_fail" class="par" style="text-align: center; margin: 0px;"></div>
    <label>注意，分数要用“整数+分子/分母"的方式表示。比如三又五分之二， 需要写作“3+2/5”；四分之三，需要写作"3/4"。
    <input class="input_class" type="text"/>
    <button class="btn_check">提交答案</button>
  </div><!-- content -->
</div><!-- page -->


</body>
</html>
